File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments