-
Notifications
You must be signed in to change notification settings - Fork 450
Expand file tree
/
Copy pathOAuthApplication.ts
More file actions
44 lines (38 loc) · 1.29 KB
/
OAuthApplication.ts
File metadata and controls
44 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ClerkRuntimeError } from '@clerk/shared/error';
import type {
ClerkResourceJSON,
FetchOAuthConsentInfoParams,
OAuthConsentInfo,
OAuthConsentInfoJSON,
} from '@clerk/shared/types';
import { BaseResource } from './internal';
export class OAuthApplication extends BaseResource {
pathRoot = '';
protected fromJSON(_data: ClerkResourceJSON | null): this {
return this;
}
static async fetchConsentInfo(params: FetchOAuthConsentInfoParams): Promise<OAuthConsentInfo> {
const { oauthClientId, scope } = params;
const json = await BaseResource._fetch<OAuthConsentInfoJSON>(
{
method: 'GET',
path: `/me/oauth/consent/${encodeURIComponent(oauthClientId)}`,
search: scope !== undefined ? { scope } : undefined,
},
{ skipUpdateClient: true },
);
if (!json) {
throw new ClerkRuntimeError('Network request failed while offline', { code: 'network_error' });
}
const envelope = json;
const data = envelope.response ?? json;
return {
oauth_application_name: data.oauth_application_name,
oauth_application_logo_url: data.oauth_application_logo_url,
oauth_application_url: data.oauth_application_url,
client_id: data.client_id,
state: data.state,
scopes: data.scopes ?? [],
};
}
}