connect function is used to authenticate with Smokeball and generate a token session for your application.
The token session provides access to short-lived access tokens that can be used to make API requests to the Smokeball API with the scopes you have configured in your Smokeball App.
Prerequisites
1. Initialize the SDK
Before using theconnect function, you must initialize the SDK.
2. Obtain an Embed Token from your Backend
Your backend will receive an embed token from Smokeball (for example, through a plugin pre-flight request). This embed token:- Has a lifetime of 1 minute
- Is tied to the logged-in user ID
- Is tied to your integrating app’s Client ID
Your backend should provide this token to your client application.
Using the Connect function
Only applications that have been configured and approved by Smokeball are able to use theconnect function.
Once you have:
- Initialized the SDK
- Obtained an embed token from your backend
connect function:
connect function accepts a request object with the following structure:
Response
Theconnect function returns a token session that exposes a token() function. This token session:
- Lasts for 1 day regardless of refresh token lifetime, requiring a new session to be generated everytime your app is loaded
- Provides access to short-lived tokens scoped to your app’s Client ID and configured scopes
Getting Access Tokens
Use thetoken() function from the token session to acquire a new short-lived access token:
The refresh token and refresh functionality are handled automatically by the SDK backend. You do not need to manage refresh tokens directly.
Complete Example
Notes
- The embed token is provided to your backend by Smokeball - typically via a secure pre-flight request, or similar integration flow. Your backend is responsible for securely receiving and passing this token to your client for SDK authentication.
- The embed token is valid for only 1 minute and can be used a single time. Be sure to use it immediately after receiving it, as it will expire quickly and cannot be reused.
- The token session created by
connectlasts for exactly 1 day, after which you must generate a new session. - Access tokens obtained via
token()are short-lived and scoped to your app’s Client ID and configured scopes.