Skip to content

Commit

Permalink
fix roblox provider
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Apr 25, 2024
1 parent 1b89fec commit b79553f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions .changesets/lmwhp.patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Roblox provider (see docs for API changes)
12 changes: 6 additions & 6 deletions docs/pages/providers/roblox.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ title: "Roblox"

# Roblox

Implements OpenID Connect. For confidential clients and not public clients.
Implements OpenID Connect.

For usage, see [OAuth 2.0 provider with PKCE](/guides/oauth2-pkce).
For usage, see [OAuth 2.0 provider](/guides/oauth2).

```ts
import { Roblox } from "arctic";
Expand All @@ -15,11 +15,11 @@ const roblox = new Roblox(clientId, clientSecret, redirectURI);
```

```ts
const url: URL = await roblox.createAuthorizationURL(state, codeVerifier, {
const url: URL = await roblox.createAuthorizationURL(state, {
// optional
scopes // "openid" always included
});
const tokens: RobloxTokens = await roblox.validateAuthorizationCode(code, codeVerifier);
const tokens: RobloxTokens = await roblox.validateAuthorizationCode(code);
const tokens: RobloxTokens = await roblox.refreshAccessToken(refreshToken);
```

Expand All @@ -28,15 +28,15 @@ const tokens: RobloxTokens = await roblox.refreshAccessToken(refreshToken);
Add the `profile` scope.

```ts
const url = await roblox.createAuthorizationURL(state, codeVerifier, {
const url = await roblox.createAuthorizationURL(state, {
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 tokens = await roblox.validateAuthorizationCode(code);
const response = await fetch("https://apis.roblox.com/oauth/v1/userinfo", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`
Expand Down
14 changes: 4 additions & 10 deletions src/providers/roblox.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TimeSpan, createDate } from "oslo";
import { OAuth2Client } from "oslo/oauth2";

import type { OAuth2ProviderWithPKCE } from "../index.js";
import type { OAuth2Provider } 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 {
export class Roblox implements OAuth2Provider {
private client: OAuth2Client;
private clientSecret: string;

Expand All @@ -19,26 +19,20 @@ export class Roblox implements OAuth2ProviderWithPKCE {

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> {
public async validateAuthorizationCode(code: string): Promise<RobloxTokens> {
const result = await this.client.validateAuthorizationCode<TokenResponseBody>(code, {
credentials: this.clientSecret,
codeVerifier
credentials: this.clientSecret
});
const tokens: RobloxTokens = {
accessToken: result.access_token,
Expand Down

0 comments on commit b79553f

Please sign in to comment.