Skip to content

Commit e5818b8

Browse files
committed
feat: initial version
1 parent 701ac51 commit e5818b8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
declare interface Options {
2+
clientId: string
3+
4+
allowSignup?: boolean
5+
login?: string
6+
scopes?: string | string[]
7+
redirectUrl?: string
8+
}
9+
10+
export interface Result {
11+
allowSignup: boolean,
12+
clientId: string,
13+
login: string | null,
14+
redirectUrl: string | null,
15+
scopes: string[],
16+
state: string,
17+
url: string
18+
}
19+
20+
const BASE_URL = 'https://github.com/login/oauth/authorize'
21+
22+
export default function login (options: Options): Result {
23+
const scopesNormalized = typeof options.scopes === 'string'
24+
? options.scopes.split(/[,\s]+/).filter(Boolean)
25+
: Array.isArray(options.scopes) ? options.scopes : []
26+
27+
return {
28+
allowSignup: options.allowSignup === false ? false : true,
29+
clientId: options.clientId,
30+
login: options.login || null,
31+
redirectUrl: options.redirectUrl || null,
32+
scopes: scopesNormalized,
33+
state: Math.random().toString(36).substr(2),
34+
url: `${BASE_URL}?client_id=${options.clientId}`
35+
}
36+
}

0 commit comments

Comments
 (0)