Skip to main content

OAuth


The OAuth framework facilitates the user authentication process. It authorizes access to the user's data from various services (such as social media platforms, cloud storage, etc.) without requiring users to reveal their login credentials.

OAuth


OAuth Properties

PropertyDescription
Disabled
[Checkbox]
Deactivates the OAuth widget.
Client IDThe unique identifier assigned to your application by the OAuth provider.
Note: To obtain a Client ID, you'll need to register your application with the provider.
Client SecretThe secret string of characters designated to the Client ID.
ScopeA list of permissions that your application requests from the OAuth provider. It determines the actions that your application can perform on behalf of the user.
StateA value sent with the OAuth request and returned by the provider in the response. It is used to confirm the request originated from your application.
Redirect URLUsers are redirected to this URL after the login authentication.
Logout
[Checkbox]
Enables "logout" (if available) from the third-party application or service.

API Methods

setDisabled

Sets the Disabled flag for this component.

setDisabled(visible: boolean): void

setVisibility

Sets the Visibility flag for this component.

setVisibility(visible: boolean): void

setVisibilityCondition

Sets the visibility condition for this component.

setVisibilityCondition(condition: string): void

Event Handlers

onLogin

onLogin - Sets the OAuth provider's "User Login" URL.

async function main(clientId, redirectUri, scope, state, asset) {
// Start of editable area
const url = `https://accounts.spotify.com/authorize?response_type=code&client_id=${clientId}&scope=${scope}&redirect_uri=${redirectUri}&state=${state}`
return url
// End of editable area
}

onToken

onToken - Generates the "Access Token" with the OAuth provider.

async function main(code, clientId, clientSecret, scope, state, redirectUri, asset) {
// Start of editable area
const params: any = {
grant_type: 'client_credentials',
code: code,
redirect_uri: "http://localhost:3000",
client_id: clientId,
client_secret: clientSecret,
}
const formData = new URLSearchParams();
Object.keys(params).forEach((key) => {
formData.append(key, params[key])
})
const response = await fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
body: formData,
headers: {
"Content-Type": 'application/x-www-form-urlencoded',
"Authorization": 'Basic ' + (window.btoa(clientId + ':' + clientSecret))
},
}).then(response => response.json())
.then(data => { return data });;
// End of editable area
}

onLogout

onLogout - Sets the "Logout" URL (revokes user-access) for the OAuth provider.

async function main(clientId, redirectUri, scope, state, asset) {
// Start of editable area
const url = `https://www.spotify.com/logout/`
return url
// End of editable area
}