- to which a Cocoon Data user account is permitted to access, and
- is represented by an access token (1) .
Working with OAuth 2.0 on the Cocoon Data Platform
The Cocoon Data API utilizes the OAuth 2.0 Authorization Framework to authenticate and authorize Cocoon Data user accounts securely to the Cocoon Data Platform. The OAuth 2.0 process (or ‘dance’) to obtain an access token (1) using the authorization code grant type (2) consists of the following steps:- Your (client) application initiates a request for an authorization code from the Cocoon Data Platform.
Note: The authorization code is a short string/code, typically alphanumeric, whose purpose is to ensure that this step (and especially the following 2) are connected. - A Cocoon Data user authenticates themselves to the Cocoon Data Platform (directly) and if this is successful, the Cocoon Data Platform sends back an authorization code to your application.
- Your application makes a subsequent request to the Cocoon Data Platform to receive an access token. This 2nd request contains the authorization code and your application’s client credentials.
* When deciding on which of these grant types to implement in your client application, the authorization code may provide more security or trust than password, in that a Cocoon Data user’s credentials are not specified directly through your client application when the user authenticates to the Cocoon Data Platform. This grant type decision would most likely amount to the level of trust that parties outside your organisation have in your application.
Registering your application on the Cocoon Data Platform
Before developing your application, you should consult your SafeShare administrator to begin the process of registering your application on the Cocoon Data Platform. After agreeing on the grant type(s) that your application will implement, your SafeShare administrator can proceed with your application’s registration process. Once your application is registered, your SafeShare administrator should securely issue you with client credentials (a client ID and client secret) to hard code into your application. These credentials are used to ‘authenticate’ your application to the Cocoon Data Platform. Be aware, however, that if your application is a native desktop/laptop, a mobile or a user agent-based application, then client credentials are less secure than they would be for a server-side web application (with properly implemented TLS). Therefore in these circumstances, your SafeShare administrator may allow you to generate your own client credentials. See Configuring client applications in the SafeShare Administrator’s Guide for more information.Overview of the OAuth 2.0 process
The following steps outline the Cocoon Data API OAuth 2.0 process for authenticating and authorizing your application to access a Cocoon Data user’s resources on the Cocoon Data Platform:- Initiating authentication and authorization (initiate the process for obtaining an access token and optional refresh token from the Cocoon Data Platform)
- Receiving the access token (the Cocoon Data Platform responds with the access token)
Initiating authentication and authorization
The authentication and authorization process begins by initiating appropriate requests to the Cocoon Data Platform to obtain an access token. The nature of these requests differs depending on one of the three supported OAuth 2.0 grant types your application has permission to use: Once the authentication and authorization process is successful, an access token is returned to your application. Pass this token in subsequent requests to the Cocoon Data Platform to perform other interactions and activities through the Cocoon Data API.Using the authorization code grant type
Step (1) To obtain an access token from the Cocoon Data Platform using the authorization code grant type, make an initialGET method request to this API endpoint:
with the following URL parameters:
response_type- Use the valuecodeclient_id- The client ID of your application’s client credentials, which would have been generated when your application was registered on the Cocoon Data Platform.redirect_uri- Your application’s URL/URI, which will handle the initial response from the Cocoon Data Platform that contains the actual authorization code. This initial response is sent after the user has successfully authenticated.
redirect_uri value above) to handle the authorization code, whose value is the code URL parameter.
For example:
POST method):
with the following parameters sent as form URL-encoded (i.e. application/x-www-form-urlencoded) data in the request’s body:
grant_type- Use the valueauthorization_codecode- The value of the authorization code returned by the Cocoon Data Platform (and initially handled by your application through the redirect URI).redirect_uri- Your application’s URL/URI that handled the initial response from the Cocoon Data Platform that contained the actual authorization code.
exampleClientApplication:exampleClientApplicationSecret
with Base64 results in the value:ZXhhbXBsZUNsaWVudEFwcGxpY2F0aW9uOmV4YW1wbGVDbGllbnRBcHBsaWNhdGlvblNlY3JldA==
Submitting a cURL command like the one above with at least one
being automatically included in the request. Be aware that this header is required for the request to succeed.
-d option results in the following header: Content-Type: application/x-www-form-urlencoded being automatically included in the request. Be aware that this header is required for the request to succeed.
Using the implicit grant type
To obtain an access token from the Cocoon Data Platform using the implicit grant type, make a singleGET method request to this API endpoint:
with the following URL parameters:
response_type- Use the valuetokenclient_id- The client ID of your application’s client credentials, which would have been generated when your application was registered on the Cocoon Data Platform.redirect_uri- Your application’s URL/URI, which will handle the response from the Cocoon Data Platform that contains the access token itself. This response is sent after the user has successfully authenticated.
Using the password grant type
To obtain an access token from the Cocoon Data Platform using the password grant type, simply make a singlePOST method request to this API endpoint:
with the following parameters sent as form URL-encoded (i.e. application/x-www-form-urlencoded) data in the request’s body:
grant_type- Use the valuepasswordusername- The email address of a Cocoon Data user’s credentials (acquired through your application).password- The password of a Cocoon Data user’s credentials (acquired through your application).
exampleClientApplication:exampleClientApplicationSecret
with Base64 results in the value:ZXhhbXBsZUNsaWVudEFwcGxpY2F0aW9uOmV4YW1wbGVDbGllbnRBcHBsaWNhdGlvblNlY3JldA==
Submitting a cURL command like the one above with at least one
being automatically included in the request. Be aware that this header is required for the request to succeed.
-d option results in the following header: Content-Type: application/x-www-form-urlencoded being automatically included in the request. Be aware that this header is required for the request to succeed.
Receiving the access token
From authorization code or password grant type requests
Once the authentication and authorization processes for either the authorization code or password grant type above is successful (via the finalPOST method request to the <access-service>/api/oauth/token API endpoint), the Cocoon Data Platform responds with an access token in the body of the response (as a JSON object) as well as a refresh token (if your registered client application on the Cocoon Data Platform has been configured to issue one).
Example response:
From implicit grant type requests
Once the authentication and authorization process for the implicit grant type above is successful (via theGET method request to the <access-service>/api/oauth/authorize API endpoint), the Cocoon Data Platform responds by redirecting to your application’s URL/URI (i.e. the redirect_uri value above) with an access token as a URL parameter (amongst other parameters).
Example response:

