Authentication

Search Alt+S

All requests to Privacy Bee’s API require the use of OAuth 2.

All authentication is user-level, and any access to any tenant (business-level) resources will require the user to have appropriate roles configured. For example, a consumer or basic employee account can access their own information, however an employee with the “Business Admin” role assigned will have full access to all resources of that business. If the authenticated user has permissions over more than one company (multiple linked business emails or through a multi-tenant business). Each company will have their own base URL that includes a company ID that can be found on the OAuth API Keys page.

Authentication tokens are short lived unless chosen specifically to last longer so if you are using the Client Credentials flow you want to check the expires_in parameter of the bearer token to determine if you need to request a new token first. If you are using Authorization Code flow you can use the refresh token in order to get a new access token.

Supported Grant Type Flows:

  • Authorization Code Flow with PKCE
    • Use Case: Manual Resource Owner Access (ex: the Buzz app, our browser extension, Vendor & Cookie Consent)
    • Supports Authorization header with bearer tokens (JWT)
  • Client Credentials Flow
    • Use Case: Backend services, CLI, scheduled access, etc.
    • Requires a Client ID and Client Secret (your Privacy Bee API Key)

Authorization Header

This is the easiest and default recommended way to interact with Privacy Bee’s V3 API. To get started, simply navigate to your organization’s “Developer API” app within Privacy Bee:

Click the blue “Generate OAuth 2 Client” button in the top right corner, then select the “Client Credentials” toggle and flip on the “Generate Long-Lived Token“:

This will create an Authorization Token that lasts forever, allowing you to immediately start passing the “Authorization” header to API requests without any further authentication or token management.

curl https://api.privacybee.com/ -H "Authorization: Bearer ${ACCESS_TOKEN}" 

Client Credentials

Client Credentials are the ideal way for machine-to-machine interactions with our API. They allow you to quickly get an authentication token to interact with our API programmatically. There are two ways of generating tokens. When you create the client on the app, you will have the option to choose Long-Lived Token. If you decide to be long-lived, you will be immediately given a bearer token without expiration. You do not need to use the following endpoints to generate new tokens.

If you do not choose Long-Lived Token (more secure), you will use the following endpoint. When you create the client, you will be given a secret. With the client_id and client_secret, you can make requests to the following endpoint to generate new access tokens.


POST /oauth/token

Parameters: The following parameters must be included in the body of the request

VariableData TypeRequiredDescription
grant_typestringYesMust be set to “client_credentials” per RFC 6749.
client_idstringYesClient ID is displayed on your API Keys page
client_secretstringYesClient secret that was generated when you created the client ID

Example Request

curl -X POST https://api.privacybee.com/oauth/token \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"

Return:

VariableData TypeDescription
token_typestringBearer
expires_instringWhen will the token expire
access_tokenstringThe bearer token you can use to interact with the API and make authenticated requests

Note: All requests need to have the Header "Authorization": "Bearer ACCESS_TOKEN"


Authorization Code

GET /oauth/authorize

This is the first step of authenticating a Resource Owner, usually via a browser login (retrieving a multi-factor PIN, SSO, SAML, OIDC, or similar)

Parameters:

VariableData TypeRequiredDescription
response_typestringYesMust be set to “code” per RFC 6749.
client_idstringNoClient ID is displayed on your API Keys page.
redirect_uristringNoThe URL to send the users in the event of successful authentication. https:// only. This must be approved for your client ID
statestringNoA unique string to be passed through to the request_uri on successful authentication, used to validate requests and prevent CSRF attacks. It must be 40-120 characters
challengestringA base 64 encoded SHA256 encryption of the state


Return:
Returns the following values, either encoded in the redirect_uri as path segments via an HTTP/302 redirect, or returned as a JSON object via an HTTP/200 (if no request_uri was specified)

FieldData TypeDescription
client_idstringPassed through ID from the request
codestringA single-use authorization code that expires 300 seconds after generation, used to exchange for an access token
statestringPassed through state variable from the request. Confirm the values match exactly to ensure no interception or manipulation has occurred
errorenumIf anything goes wrong during the authorization, the error variable will be returned with one of the following values: invalid_request, unauthorized_client, access_denied, unsupported_response_type, server_error, or temporarily_unavailable (per RFC 6749 4.1.2.1)
error_descriptionstringIf anything goes wrong during the authorization, this human-readable description will be populated

POST /oauth/token

Get an access token using the code returned from /oauth/authorize

Parameters:

VariableData TypeRequiredDescription
grant_typestringYes"authorization_code"
response_typestringYes"code"
client_idstringYesOAuth Client ID
redirect_urlstringYesMust match redirect URI of the client ID
code_verifierstringYesSee RFC 7636 specification, this is the code that was used to generate the challenge in the /oauth/authorize step
codestringYesAuthorization code returned in the first step

Return:

VariableData TypeDescription
token_typestring"Bearer"
expires_inintegerTime until the access_token expires
access_tokenstringAccess token to be used in requests
refresh_tokenstringCan be used to get a new refresh token

POST /oauth/token

You can also use this same endpoint to refresh tokens.

VariableData TypeRequiredDescription
grant_typestringYes"refresh_token"
refresh_tokenstringYesThe refresh token
client_idstringYesOAuth Client ID

Return:

VariableData TypeDescription
token_typestringBearer"
expires_inintegerTime until the access_token expires
access_tokenstringAccess token to be used in requests
refresh_tokenstringCan be used to get a new refresh token