@@ -42,24 +42,32 @@ export const createCallbackEndpoint = (
42
42
// obtain access token
43
43
// /////////////////////////////////////
44
44
45
- const tokenResponse = await fetch ( pluginOptions . tokenEndpoint , {
46
- method : "POST" ,
47
- headers : {
48
- "Content-Type" : "application/x-www-form-urlencoded" ,
49
- Accept : "application/json" ,
50
- } ,
51
- body : new URLSearchParams ( {
52
- code,
53
- client_id : pluginOptions . clientId ,
54
- client_secret : pluginOptions . clientSecret ,
55
- redirect_uri : redirectUri ,
56
- grant_type : "authorization_code" ,
57
- } ) . toString ( ) ,
58
- } ) ;
59
- const tokenData = await tokenResponse . json ( ) ;
60
- const access_token = tokenData ?. access_token ;
45
+ let access_token : string ;
46
+
47
+ if ( pluginOptions . getToken ) {
48
+ access_token = pluginOptions . getToken ( code ) ;
49
+ } else {
50
+ const tokenResponse = await fetch ( pluginOptions . tokenEndpoint , {
51
+ method : "POST" ,
52
+ headers : {
53
+ "Content-Type" : "application/x-www-form-urlencoded" ,
54
+ Accept : "application/json" ,
55
+ } ,
56
+ body : new URLSearchParams ( {
57
+ code,
58
+ client_id : pluginOptions . clientId ,
59
+ client_secret : pluginOptions . clientSecret ,
60
+ redirect_uri : redirectUri ,
61
+ grant_type : "authorization_code" ,
62
+ } ) . toString ( ) ,
63
+ } ) ;
64
+ const tokenData = await tokenResponse . json ( ) ;
65
+
66
+ access_token = tokenData ?. access_token ;
67
+ }
68
+
61
69
if ( typeof access_token !== "string" )
62
- throw new Error ( `No access token: ${ JSON . stringify ( tokenData ) } ` ) ;
70
+ throw new Error ( `No access token: ${ access_token } ` ) ;
63
71
64
72
// /////////////////////////////////////
65
73
// get user info
0 commit comments