Smore API Help

OAuth2 Authentication Process

How to Obtain a Token Using OAuth2

Redirecting Users to the Authorization Page

When your application needs to access a user's Smore account data, you need to redirect the user from your application to Smore's authorization page at https://smore.im/authorize. You need to construct a URL containing the following parameters:

response_type

This parameter specifies the OAuth2 authorization code flow your application will use, and the value of this parameter should always be code.

client_id

The client ID of your application.

redirect_uri

After user authorization, Smore will redirect the user back to your application along with an authorization code. This parameter specifies the URL Smore will use to redirect users back to your application.

scope

This parameter specifies the permissions of Smore API your application will access. If multiple permissions are required, separate them with a comma (,). Refer to the Scopes section for more information.

state

This parameter is optional. If your application needs to pass some data back to your application when the user is redirected, you can use this parameter.

For example, if the client ID of your application is 12345abcde, your application's redirect URL is https://example.com/oauth/callback, and your application requires forms:read and responses:read permissions, then your authorization URL will be:

https://smore.im/authorize? response_type=code& client_id=12345abcde& redirect_uri=https%3A%2F%2Fexample.com%2Foauth%2Fcallback& scope=forms:read,responses:read& state=abcdefg

You need to redirect users to this URL, so they can authorize your application to access their Smore account data on Smore. When users are redirected to this URL, they will be asked to log in to Smore (if they are not already logged in), and then they will see the following page:

Smore OAuth2 Authorization Page

Obtaining Access Token from Smore

After the user clicks the "Allow Access" button, Smore will redirect the user to your specified redirect_url, along with an authorization code code. For instance, in the above example, if the user agrees to authorize, Smore will redirect the user to:

https://example.com/oauth/callback?code=abcdef12345&state=abcdefg

Your application needs to use this authorization code to request an access token from Smore. You need to send a POST request to https://smore.im/api/oauth2/token with the following parameters:

grant_type

This parameter specifies the OAuth2 authorization code flow your application will use, and the value of this parameter should always be authorization_code.

code

The authorization code `code` received from Smore by your application.

client_id

The client ID of your application.

client_secret

The client secret of your application.

redirect_uri

The redirect URL you used in the previous step.

For example, if the client ID of your application is 12345abcde, your application's client secret is 12345abcde, your application's redirect URL is https://example.com/oauth/callback, and the authorization code received from Smore is abcdef12345, then your request will be:

POST /api/oauth2/token HTTP/1.1 Host: smore.im Content-Type: application/x-www-form-urlencoded grant_type=authorization_code& code=abcdef12345& client_id=12345abcde& client_secret=12345abcde& redirect_uri=https://example.com/oauth/callback
curl -X POST https://smore.im/api/oauth2/token \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code&code=abcdef12345&client_id=12345abcde&client_secret=12345abcde&redirect_uri=https://example.com/oauth/callback"
const response = await fetch('https://smore.im/api/oauth2/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ grant_type: 'authorization_code', code: 'abcdef12345', client_id: '12345abcde', client_secret: '12345abcde', redirect_uri: 'https://example.com/oauth/callback', }), }); const data = await response.json();
import requests url = 'https://smore.im/api/oauth2/token' payload = { 'grant_type': 'authorization_code', 'code': 'abcdef12345', 'client_id': '12345abcde', 'client_secret': '12345abcde', 'redirect_uri': 'https://example.com/oauth/callback' } response = requests.post(url, data=payload) print(response.json())

If your request is successful, you will receive a JSON object containing information about the access token:

{ // Access Token "access_token": "r3YMg2RhzbQfcjjLrJVOOa3feok21hN7", // Refresh Token "refresh_token": "oSCpXMe73fP7SVM7ORpgnh02NENHiuur", // Token Type "token_type": "Bearer", // Token Expiration Time "expires_in": 3600, // Authorization Scope "scope": "forms:read,responses:read", // User of the Token "user": "account@smore.im" }

After receiving the access token, you can try to access /api/v1/me to verify that your access token is valid.

Using Access Token to Access Smore API

When your application needs to access the Smore API, you need to include your access token in the request header. If you need to use a specific API endpoint (like /api/v1/me), and the user's access token is r3YMg2RhzbQfcjjLrJVOOa3feok21hN7, your request will be like:

GET /api/v1/me HTTP/1.1 Host: smore.im Accept: application/json Authorization: Bearer r3YMg2RhzbQfcjjLrJVOOa3feok21hN7
curl -X GET https://smore.im/api/v1/me \ -H "Accept: application/json" \ -H "Authorization: Bearer r3YMg2RhzbQfcjjLrJVOOa3feok21hN7"
const response = await fetch('https://smore.im/api/v1/me', { headers: { Accept: 'application/json', Authorization: 'Bearer r3YMg2RhzbQfcjjLrJVOOa3feok21hN7', } }); const data = await response.json();
import requests url = 'https://smore.im/api/v1/me' headers = { 'Accept': 'application/json', 'Authorization': 'Bearer r3YMg2RhzbQfcjjLrJVOOa3feok21hN7' } response = requests.get(url, headers=headers) print(response.json())

Refresh Token

When the access token expires, you will receive a 401 Unauthorized status code in the API response. At this point, you need to use a refresh token to request a new access token.

You need to send a POST request to https://smore.im/api/oauth2/refresh with the following parameters:

grant_type

The value of this parameter should always be refresh_token.

refresh_token

The refresh token `refresh_token` your application received from Smore.

client_id

The client ID of your application.

client_secret

The client secret of your application.

For example, if your application's client ID is 12345abcde, your application's client secret is 12345abcde, and the refresh token your application received from Smore is oSCpXMe73fP7SVM7ORpgnh02NENHiuur, then your request would be:

POST /api/oauth2/refresh HTTP/1.1 Host: smore.im Content-Type: application/x-www-form-urlencoded grant_type=refresh_token& refresh_token=oSCpXMe73fP7SVM7ORpgnh02NENHiuur& client_id=12345abcde& client_secret=12345abcde
curl -X POST https://smore.im/api/oauth2/refresh \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=refresh_token&refresh_token=oSCpXMe73fP7SVM7ORpgnh02NENHiuur&client_id=12345abcde&client_secret=12345abcde"
const response = await fetch('https://smore.im/api/oauth2/refresh', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: 'oSCpXMe73fP7SVM7ORpgnh02NENHiuur', client_id: '12345abcde', client_secret: '12345abcde', }), }); const data = await response.json();
import requests url = 'https://smore.im/api/oauth2/token' payload = { 'grant_type': 'refresh_token', 'refresh_token': 'oSCpXMe73fP7SVM7ORpgnh02NENHiuur', 'client_id': '12345abcde', 'client_secret': '12345abcde', } response = requests.post(url, data=payload) print(response.json())

If the request is successful, you will receive an object containing the new access_token.

{ // New access token "access_token": "ev0LsPS4zA9fqKUepX6CSgEJaj01R3qa", // Refresh token "refresh_token": "oSCpXMe73fP7SVM7ORpgnh02NENHiuur", // Token type "token_type": "Bearer", // Token expiration time "expires_in": 3600, // Authorized scope "scope": "forms:read,responses:read", // User owning the token "user": "account@smore.im" }
Last modified: 08 December 2023