OAuth must be used with HTTPS.
OAuth is insecure if it is performed without TLS. Only use HTTPS for your client redirect URIs.
Step 1: Request authorization
The first step is for the client to request authorization from the user. This is done by redirecting the user to Smile’s authorization page with the appropriate query parameters.Step 2: Validate authorization code
After a user has approved or denied the authorization request, they will be redirected back to one of the app’s whitelisted redirect URIs. If a redirect URI was provided during the authorization request, the user will be redirect there. Otherwise, they will be redirected to the first redirect URI in the app’s settings in the Partner Portal. The following example demonstrates the format of the URL and the parameters that will be included when redirecting after an authorization request:
Before continuing, your app should do one of two things:
- If an
errorparameter is present, gracefully handle the error and present an informative UI to the user. - Otherwise, validate that the
stateparameter matches the value you passed in Step 1 when first making the authorization request. If this validation is successful, proceed to the next step to get an access token. If this validation is unsuccessful, return an error to the user and restart the OAuth process.
Step 3: Get an access token
To exchange an authorization code for an access token, a server-to-server request must be made. The request must be made using Basic HTTP Authentication with the Client ID as the user-ID and the Client Secret as the password. These values can be found in the app’s settings in the Partner Portal. The request will look like the following example and should also include the relevant parameters in the body:
The token exchange request will respond with a JSON payload that represents an access token and looks like the following:
JSON
Step 4: Using the access token
The access token received during the previous step allows the app to make authorized requests to Smile on behalf of the specified account. It will never return data for any other Smile accounts. In order to make an authorized request to Smile’s REST API, include the access token in theAuthorization header of a given request. Note that when using the access token, the authorization type is “Bearer”. This corresponds to the token_type from the response in the previous step.
For example, to retrieve a list of the account’s customers, the following request could be made:
cURL
Step 5: Refreshing an access token
If a request is made with an expired access token, it will return a401 Unauthorized response. When this happens, the app can use it’s refresh token to obtain a new access token.
Access tokens always have an expiration. We suggest the following pattern for determining when you should refresh your access token:
- Upon receiving the access token, store the time at which it will expire (represented by the
expires_inattribute). - Before making a request, if the time the token is expected to expire at is within five minutes of the current time, refresh the token.
The token refresh request will respond with a JSON payload representing an access token. It’s format and keys will be identical to Step 3.