Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ describe('startOpenAiChatGptConnect', () => {
expect(signIn).toHaveBeenCalledWith(
'openai',
{ callbackUrl: '/byok' },
{ scope: OPENAI_TOKEN_SHARING_SCOPE }
{ scope: OPENAI_TOKEN_SHARING_SCOPE, force_reconsent: 'true' }
);
expect(createLinkingSession.mock.invocationCallOrder[0]).toBeLessThan(
signIn.mock.invocationCallOrder[0]
Expand All @@ -498,7 +498,7 @@ describe('startOpenAiChatGptConnect', () => {
expect(signIn).toHaveBeenCalledWith(
'openai',
{ callbackUrl: '/organizations/00000000-0000-4000-8000-000000000001/byok' },
{ scope: OPENAI_TOKEN_SHARING_SCOPE }
{ scope: OPENAI_TOKEN_SHARING_SCOPE, force_reconsent: 'true' }
);
});

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/lib/auth/openai/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('OpenAI OAuth config', () => {
'email',
'offline_access',
'resource.invoke',
'chatpass.enable.request',
'chatgpt.tokens.use.obo',
]);
expect(OPENAI_RESOURCE).toBe('https://api.openai.com/v1');
});
Expand All @@ -66,7 +66,7 @@ describe('OpenAI OAuth config', () => {
);
// A grant that can call the resource and refresh, but that declined the
// ChatGPT allowance consent, must stay an identity sign-in: token sharing
// cannot spend the allowance without `chatpass.enable.request`.
// cannot spend the allowance without `chatgpt.tokens.use.obo`.
expect(
isOpenAiTokenSharingGrant({
scope: 'openid profile email resource.invoke offline_access',
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/auth/openai/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export async function startOpenAiChatGptConnect(
await signIn(
'openai',
{ callbackUrl: openAiChatGptByokPath(organizationId) },
{ scope: OPENAI_TOKEN_SHARING_SCOPE }
{ scope: OPENAI_TOKEN_SHARING_SCOPE, force_reconsent: 'true' }
);
}
6 changes: 3 additions & 3 deletions apps/web/src/lib/auth/openai/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ export const OPENAI_IDENTITY_SCOPE = 'openid profile email';

/** Token-sharing scopes, used once a client is approved for delegated access. */
export const OPENAI_TOKEN_SHARING_SCOPE =
'openid profile email offline_access resource.invoke chatpass.enable.request';
'openid profile email offline_access resource.invoke chatgpt.tokens.use.obo';

/** The API resource that token sharing targets. */
export const OPENAI_RESOURCE = 'https://api.openai.com/v1';

/**
* The scopes that make a grant a delegated BYOK credential rather than an
* identity-only sign-in. `resource.invoke` is what permits calling the API
* resource on the person's behalf, `chatpass.enable.request` is the consent to
* resource on the person's behalf, `chatgpt.tokens.use.obo` is the consent to
* spend the person's ChatGPT allowance, and `offline_access` is what makes the
* token renewable without another sign-in. An identity-only sign-in grants
* none of them, and a person can decline token sharing while still granting
* identity, so the allowance consent must be checked on its own.
*/
const OPENAI_DELEGATED_GRANT_SCOPES = [
'resource.invoke',
'chatpass.enable.request',
'chatgpt.tokens.use.obo',
'offline_access',
] as const;

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/lib/user/server-signin-callback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe('authOptions.callbacks.signIn auto-link wiring', () => {
type: 'oauth',
access_token: 'access-token',
refresh_token: 'refresh-token',
scope: 'openid profile email offline_access resource.invoke chatpass.enable.request',
scope: 'openid profile email offline_access resource.invoke chatgpt.tokens.use.obo',
},
profile: { sub: 'openai-sub', email: 'sso-link@example.com' },
} as never);
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('authOptions.callbacks.signIn auto-link wiring', () => {
type: 'oauth',
access_token: 'access-token',
refresh_token: 'refresh-token',
scope: 'openid profile email offline_access resource.invoke chatpass.enable.request',
scope: 'openid profile email offline_access resource.invoke chatgpt.tokens.use.obo',
},
profile,
} as never);
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('authOptions.callbacks.signIn auto-link wiring', () => {
type: 'oauth',
access_token: 'access-token',
refresh_token: 'refresh-token',
scope: 'openid profile email offline_access resource.invoke chatpass.enable.request',
scope: 'openid profile email offline_access resource.invoke chatgpt.tokens.use.obo',
},
profile: { sub: 'openai-shared-services-sub', email: 'shared-services@example.com' },
} as never);
Expand Down