-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoogle.ts
66 lines (56 loc) · 1.68 KB
/
google.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { TOAuth2Provider } from '..'
import { env } from '../utils'
/**
* @see https://developers.google.com/identity/protocols/oauth2/web-server#httprest_1
*/
type TGoogleParams<AccessType extends string, Prompt extends string> = {
/**
* Indicates whether your application can refresh access tokens when the user is not present at the browser
*/
access_type?: 'online' | 'offline' | AccessType
/**
* Enables applications to use incremental authorization to request access to additional scopes in context
*/
include_granted_scopes?: boolean
/**
* Used to pre-fill the `username` or `email` field of the sign-in page for the user
*/
login_hint?: string
/**
* Used to control the prompt behavior
*/
prompt?: 'none' | 'consent' | 'select_account' | Prompt
}
export function google<AccessType extends string, Prompt extends string>({
access_type,
include_granted_scopes,
login_hint,
prompt
}: TGoogleParams<AccessType, Prompt> = {}): TOAuth2Provider {
const authParams: TGoogleParams<AccessType, Prompt> = {}
if (typeof access_type === 'string') {
authParams.access_type = access_type
}
if (typeof include_granted_scopes === 'boolean') {
authParams.include_granted_scopes = include_granted_scopes
}
if (typeof login_hint === 'string') {
authParams.login_hint = login_hint
}
if (typeof prompt === 'string') {
authParams.prompt = prompt
}
const provider: TOAuth2Provider = {
clientId: env('GOOGLE_OAUTH_CLIENT_ID'),
clientSecret: env('GOOGLE_OAUTH_CLIENT_SECRET'),
auth: {
url: 'https://accounts.google.com/o/oauth2/v2/auth',
params: authParams
},
token: {
url: 'https://accounts.google.com/o/oauth2/token',
params: {}
}
}
return provider
}