Sign-ins
Let people sign in to Spotify, Discord, Twitch or YouTube without an app of their own.
Services such as Spotify only let registered apps in, and an app's secret can't be in a plugin, where
anyone could read it. sdeck has apps of its own for Spotify, Discord, Twitch and YouTube. Their
secrets stay on api.sdeck.one, and your plugin gets the tokens:
const signIn = plugin.command({
id: "sign-in",
name: "Sign in",
run: async (context) => {
const { url, tokens } = await context.oauth.start("spotify", {
scopes: ["user-read-playback-state"],
});
// They come when the user is done in the browser.
tokens.then(
async ({ accessToken, refreshToken, expiresAt }) => {
await context.secrets.set("refresh", refreshToken);
context.status("Signed in", "ok");
},
(error) => context.status(error.message, "error"),
);
return url; // opened in the browser
},
});Access tokens run out. Get a new one with the refresh token:
const tokens = await context.oauth.refresh("spotify", refreshToken);
if (tokens.refreshToken) await context.secrets.set("refresh", tokens.refreshToken);tokensrejects when the user declines, or does not finish within ten minutes. Starting again ends the sign-in before it.refreshthrows anOAuthError. Itscodeis"invalid_grant"when the access was taken away: ask the user to sign in again. Any other code may pass.clientIdis the app the tokens belong to. Twitch wants it with every request.youtubeneeds a Studio newer than 0.6.0. Everyone who signs in through it shares one daily limit, so read seldom.- It needs the
networkpermission, and"apiVersion": 5. - Only the scopes sdeck's apps were made for can be asked for. If yours is missing, use an app of your own, or of the user's.
Keep a way around it
Offer a setting for the user's own client id as well, and use that when it is filled in. Sign-ins then don't depend on sdeck's servers, and someone with their own limits or app can use them. The official Spotify, Discord, Twitch and YouTube plugins do both.