@@ -3,18 +3,24 @@ import uuidv4 from 'uuid/v4';
3
3
import config from '../../common/config' ;
4
4
import { getUrlQuery } from '../../common/utils' ;
5
5
6
- const redirectUrl = `https://${ config . app . id } .chromiumapp.org/` ;
6
+ const authConfig = config . auths [ process . env . BROWSER ] ;
7
+ const { clientId, clientSecret } = authConfig ;
8
+
9
+ const redirectUrl = ( process . env . BROWSER === 'firefox' )
10
+ ? browser . identity . getRedirectURL ( )
11
+ : `https://${ config . app . ids . chrome } .chromiumapp.org/` ;
12
+ console . log ( 'OAUTH REDIRECT URL' , redirectUrl ) ;
7
13
8
14
const scope = 'gist' ;
9
15
const getAuthUrl = state => 'https://github.com/login/oauth/authorize?' +
10
- `client_id=${ encodeURIComponent ( config . auth . clientId ) } &` +
16
+ `client_id=${ encodeURIComponent ( clientId ) } &` +
11
17
`scope=${ encodeURIComponent ( scope ) } &` +
12
18
`state=${ encodeURIComponent ( state ) } &` +
13
19
`redirect_uri=${ redirectUrl } ` ;
14
20
15
21
const getAccessTokenUrl = ( code , state ) => 'https://github.com/login/oauth/access_token?' +
16
- `client_id=${ encodeURIComponent ( config . auth . clientId ) } &` +
17
- `client_secret=${ encodeURIComponent ( config . auth . clientSecret ) } &` +
22
+ `client_id=${ encodeURIComponent ( clientId ) } &` +
23
+ `client_secret=${ encodeURIComponent ( clientSecret ) } &` +
18
24
`code=${ encodeURIComponent ( code ) } &` +
19
25
`state=${ encodeURIComponent ( state ) } &` +
20
26
`redirect_uri=${ redirectUrl } ` ;
@@ -45,10 +51,10 @@ function getAccessToken(code, state) {
45
51
}
46
52
47
53
function revokeAccessToken ( accessToken ) {
48
- return fetch ( `https://api.github.com/applications/${ config . auth . clientId } /tokens/${ accessToken } ` , {
54
+ return fetch ( `https://api.github.com/applications/${ clientId } /tokens/${ accessToken } ` , {
49
55
method : 'DELETE' ,
50
56
headers : {
51
- Authorization : `Basic ${ btoa ( config . auth . clientId + ':' + config . auth . clientSecret ) } ` ,
57
+ Authorization : `Basic ${ btoa ( clientId + ':' + clientSecret ) } ` ,
52
58
} ,
53
59
} ) . then ( response => {
54
60
// 404 here just means that the user is already logged out
0 commit comments