oauth
Add OAuth functionality to your extension to access resources from a service on the user’s behalf. The Alt. app currently only support PKCE flow. To see if a provider is supporting PKCE flow, check if there is a code_challenge
and code_verifier
on their OAuth doc.
Functions
oauth.createPKCE
createPKCE(provider: OAuthProvider): OAuthPKCEClient
Create PKCE client.
Classes
OAuthPKCEClient
OAuthPKCEClient.startAuth
startAuth(): Promise<OAuthPKCERequest>;
Start the OAuth authorization.
OAuthPKCEClient.getToken
getToken(): Promise<OAuthTokenStorageValue | null>;
Get the stored OAuth token.
OAuthPKCEClient.setToken
setToken(token: OAuthToken | OAuthTokenResponse): Promise<OAuthTokenStorageValue>;
Store the OAuth token.
OAuthPKCEClient.removeToken
removeToken(): Promise<void>
Remove the OAuth token.
Example
Spotify OAuth
Google OAuth
To use PKCE flow with Google OAuth, you must select the iOS
application type when creating a new OAuth client ID.
Types
oauth.OAuthPKCEClientOptions
The options when creating a PKCE client.
Property | Type | Description |
---|---|---|
scope | string | The OAuth client’s scope |
clientId | string | The OAuth client Id |
authorizeUrl | string | The authorization URL of the OAuth service provider |
redirectMethod | OAuthRedirect | The OAuth redirect method. Default to Web |
extraParams | ?Record<string, string> | Additional parameters to be added in the authorization URL |
OAuthRedirect
Redirect methods for the OAuth flow
Name | Description |
---|---|
Web | Configure /oauth/redirect/extension as the redirect URL in the OAuth provider. |
AppUrl | Configure com.altdot-app:/oauth2callback as the redirect URL in the OAuth provider. |
DeepLink | Configure altdot-app://oauth/redirect as the redirect URL in the OAuth provider. |
oauth.OAuthProvider
The options for creating an OAuth provider.
Property | Type | Description |
---|---|---|
key | string | Unique id for the provider |
name | string | Name of the provider that will be displayed to the user |
icon | string | Icon of the provider |
description | ?string | Short description of the provider |
documentationUrl | ?string | URL to the provider documentation |
client | OAuthPKCEClientOptions | The OAuth client data |
oauth.OAuthPKCERequest
Value returned by the startAuth
method
Property | Type | Description |
---|---|---|
code | string | Code from the OAuth provider |
redirectUri | string | The OAuth’s redirect uri |
codeVerifier | string | The PKCE code verifier |
codeChallenge | string | The PKCE code challenge |
oauth.OAuthToken
Contains information about the OAuth token
Property | Type | Description |
---|---|---|
accessToken | string | The OAuth’s access token |
scope | ?string | The OAuth’s scope |
expiresIn | ?number | The lifetime in seconds of the access token |
refreshToken | ?string | The OAuth’s refresh token |
oauth.OAuthTokenStorageValue
Contains information about the stored OAuth token in storage.
Property | Type | Description |
---|---|---|
accessToken | string | The OAuth’s access token |
expiresTimestamp | number | The expires timestamp of the access token |
scope | ?string | The OAuth’s scope |
expiresIn | ?number | The lifetime in seconds of the access token |
refreshToken | ?string | The OAuth’s refresh token |
oauth.OAuthTokenResponse
Standard response when making an OAuth token request
Property | Type | Description |
---|---|---|
access_token | string | The OAuth’s access token |
scope | ?string | The OAuth’s scope |
expires_in | ?number | The lifetime in seconds of the access token |
refresh_token | ?string | The OAuth’s refresh token |