-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add Roblox provider. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Add VK provider. | ||
Add VK provider. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
github: pilcrowOnPaper | ||
github: pilcrowOnPaper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: "Roblox" | ||
--- | ||
|
||
# Roblox | ||
|
||
Implements OpenID Connect. For confidential clients and not public clients. | ||
|
||
For usage, see [OAuth 2.0 provider with PKCE](/guides/oauth2-pkce). | ||
|
||
```ts | ||
import { Roblox } from "arctic"; | ||
|
||
const roblox = new Roblox(clientId, clientSecret, redirectURI); | ||
``` | ||
|
||
```ts | ||
const url: URL = await roblox.createAuthorizationURL(state, codeVerifier, { | ||
// optional | ||
scopes // "openid" always included | ||
}); | ||
const tokens: RobloxTokens = await roblox.validateAuthorizationCode(code, codeVerifier); | ||
const tokens: RobloxTokens = await roblox.refreshAccessToken(refreshToken); | ||
``` | ||
|
||
## Get user profile | ||
|
||
Add the `profile` scope. | ||
|
||
```ts | ||
const url = await roblox.createAuthorizationURL(state, codeVerifier, { | ||
scopes: ["profile"] | ||
}); | ||
``` | ||
|
||
Parse the ID token or use the [`userinfo` endpoint](https://create.roblox.com/docs/cloud/reference/oauth2#get-v1userinfo). | ||
|
||
```ts | ||
const tokens = await roblox.validateAuthorizationCode(code, codeVerifier); | ||
const response = await fetch("https://apis.roblox.com/oauth/v1/userinfo", { | ||
headers: { | ||
Authorization: `Bearer ${tokens.accessToken}` | ||
} | ||
}); | ||
const user = await response.json(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { TimeSpan, createDate } from "oslo"; | ||
import { OAuth2Client } from "oslo/oauth2"; | ||
|
||
import type { OAuth2ProviderWithPKCE } from "../index.js"; | ||
|
||
const authorizeEndpoint = "https://apis.roblox.com/oauth/v1/authorize"; | ||
const tokenEndpoint = "https://apis.roblox.com/oauth/v1/token"; | ||
|
||
export class Roblox implements OAuth2ProviderWithPKCE { | ||
private client: OAuth2Client; | ||
private clientSecret: string; | ||
|
||
constructor(clientId: string, clientSecret: string, redirectURI: string) { | ||
this.client = new OAuth2Client(clientId, authorizeEndpoint, tokenEndpoint, { | ||
redirectURI | ||
}); | ||
this.clientSecret = clientSecret; | ||
} | ||
|
||
public async createAuthorizationURL( | ||
state: string, | ||
codeVerifier: string, | ||
options?: { | ||
scopes?: string[]; | ||
} | ||
): Promise<URL> { | ||
const scopes = options?.scopes ?? []; | ||
return await this.client.createAuthorizationURL({ | ||
state, | ||
codeVerifier, | ||
scopes: [...scopes, "openid"] | ||
}); | ||
} | ||
|
||
public async validateAuthorizationCode( | ||
code: string, | ||
codeVerifier: string | ||
): Promise<RobloxTokens> { | ||
const result = await this.client.validateAuthorizationCode<TokenResponseBody>(code, { | ||
credentials: this.clientSecret, | ||
codeVerifier | ||
}); | ||
const tokens: RobloxTokens = { | ||
accessToken: result.access_token, | ||
refreshToken: result.refresh_token, | ||
accessTokenExpiresAt: createDate(new TimeSpan(result.expires_in, "s")), | ||
idToken: result.id_token | ||
}; | ||
return tokens; | ||
} | ||
|
||
public async refreshAccessToken(refreshToken: string): Promise<RobloxTokens> { | ||
const result = await this.client.refreshAccessToken<TokenResponseBody>(refreshToken, { | ||
credentials: this.clientSecret | ||
}); | ||
const tokens: RobloxTokens = { | ||
accessToken: result.access_token, | ||
refreshToken: result.refresh_token, | ||
accessTokenExpiresAt: createDate(new TimeSpan(result.expires_in, "s")), | ||
idToken: result.id_token | ||
}; | ||
return tokens; | ||
} | ||
} | ||
|
||
interface TokenResponseBody { | ||
access_token: string; | ||
refresh_token: string; | ||
expires_in: number; | ||
id_token: string; | ||
} | ||
|
||
export interface RobloxTokens { | ||
accessToken: string; | ||
refreshToken: string; | ||
accessTokenExpiresAt: Date; | ||
idToken: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters