App Authentication with OAuth2
This documentation describes the how to get your app authenticated with CloudApps via OAuth2.
Quick start
If you are already familiar with OAuth2 and the use of Authorization Code Grant, here is the quick list of required information.
Key | Value |
---|---|
Authorize endpoint | https://api.cloudprinter.com/cloudauth/1.0/oauth2/authorize |
Access Token endpoint | https://api.cloudprinter.com/cloudauth/1.0/oauth2/token |
Scope | Set to "read" or "read-write" depending on the access level needed |
Client id | From app registration - Read more |
Client secret | From app registration - Read more |
If you still need more information, then read the next sections.
Authentication flow overview
Here is a quick overview of the authentication flow for OAuth2 authentication with CloudApps for Connected Apps:
Authorization code: Call the authorize endpoint. Here the end user will be requested to login and grant your app access to Cloudprinter.com resources.
Access Token: With the Authorization Code call the Access Token exchange endpoint. Once validated the we return an Access Token and a Refresh Token.
On each request to the CloudApps API the Access Token must be included.
Authentication flow details
Now lets go more in details on each step and go through the information your app need to include in each call to the Cloudprinter.com Cloudauth and CloudApps API's
Step 1 - Authorization Code
To get the Authorization Code call the authorize endpoint. Here the end user will be requested to login and grant your app access to Cloudprinter.com resources.
Endpoint: https://api.cloudprinter.com/cloudauth/1.0/oauth2/authorize
In this call you include the following parameters:
Key | Value |
---|---|
client_id | The client id given at app registration |
redirect_uri | Your apps redirect URL, will be matched against the redirect URL given at app registration |
state | Your reference, which will be included unchanged on the redirect URL |
scope | Set to "read" or "read-write" depending on the access level needed |
response_type | "code" |
Step 2 - Access Token
When you have an Authorization Code you exchange it to an Access Code by posting to the token endpoint. This will return the Access token you include as a Bearer token in the header of all calls to the CloudApps API. Make sure that you use Content-Type: application/x-www-form-urlencoded in header of request.
Endpoint: https://api.cloudprinter.com/cloudauth/1.0/oauth2/token
In this call you include the following parameters:
Key | Value |
---|---|
code | The authorization code created in step 1 |
client_id | The client id given at app registration |
client_secret | The client secret given at app registration |
redirect_uri | Your apps redirect URL, will be matched against the redirect URL given at app registration |
grant_type | "authorization_code" |
Step 3 - Call the API
Now you have been Authenticated and can start using the CloudApps API.
You include the Access Token in the header of all calls to the CloudApps API as a Bearer token.
Key | Value |
---|---|
Authorization | Bearer access token, e.g. "Bearer e09d52fd0e3def4a5c32d58e056795dbfaff34a1" |