1- import { generateCodeChallenge , verifier } from ' ./oauth-pkce' ;
1+ import { generateCodeChallenge , verifier } from " ./oauth-pkce" ;
22
33const {
4+ DEV ,
45 PHANPY_CLIENT_NAME : CLIENT_NAME ,
56 PHANPY_WEBSITE : WEBSITE ,
6- PHANPY_SCHEME : SCHEME = ' https' ,
7+ PHANPY_SCHEME : SCHEME = " https" ,
78} = import . meta. env ;
89
9- const SCOPES = ' read write follow push' ;
10+ const SCOPES = " read write follow push" ;
1011
1112/*
1213 PHANPY_WEBSITE is set to the default official site.
@@ -33,9 +34,9 @@ export async function registerApplication({ instanceURL }) {
3334 const registrationResponse = await fetch (
3435 `${ SCHEME } ://${ instanceURL } /api/v1/apps` ,
3536 {
36- method : ' POST' ,
37+ method : " POST" ,
3738 headers : {
38- ' Content-Type' : ' application/x-www-form-urlencoded' ,
39+ " Content-Type" : " application/x-www-form-urlencoded" ,
3940 } ,
4041 body : registrationParams . toString ( ) ,
4142 } ,
@@ -54,13 +55,13 @@ export async function getPKCEAuthorizationURL({
5455 const codeChallenge = await generateCodeChallenge ( codeVerifier ) ;
5556 const params = new URLSearchParams ( {
5657 client_id,
57- code_challenge_method : ' S256' ,
58+ code_challenge_method : " S256" ,
5859 code_challenge : codeChallenge ,
5960 redirect_uri : REDIRECT_URI ,
60- response_type : ' code' ,
61+ response_type : " code" ,
6162 scope : SCOPES ,
6263 } ) ;
63- if ( forceLogin ) params . append ( ' force_login' , true ) ;
64+ if ( forceLogin ) params . append ( " force_login" , true ) ;
6465 const authorizationURL = `https://${ instanceURL } /oauth/authorize?${ params . toString ( ) } ` ;
6566 return [ authorizationURL , codeVerifier ] ;
6667}
@@ -75,9 +76,9 @@ export async function getAuthorizationURL({
7576 scope : SCOPES ,
7677 redirect_uri : REDIRECT_URI ,
7778 // redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
78- response_type : ' code' ,
79+ response_type : " code" ,
7980 } ) ;
80- if ( forceLogin ) authorizationParams . append ( ' force_login' , true ) ;
81+ if ( forceLogin ) authorizationParams . append ( " force_login" , true ) ;
8182 const authorizationURL = `${ SCHEME } ://${ instanceURL } /oauth/authorize?${ authorizationParams . toString ( ) } ` ;
8283 return authorizationURL ;
8384}
@@ -92,22 +93,22 @@ export async function getAccessToken({
9293 const params = new URLSearchParams ( {
9394 client_id,
9495 redirect_uri : REDIRECT_URI ,
95- grant_type : ' authorization_code' ,
96+ grant_type : " authorization_code" ,
9697 code,
9798 // scope: SCOPES, // Not needed
9899 // client_secret,
99100 // code_verifier,
100101 } ) ;
101102 if ( client_secret ) {
102- params . append ( ' client_secret' , client_secret ) ;
103+ params . append ( " client_secret" , client_secret ) ;
103104 }
104105 if ( code_verifier ) {
105- params . append ( ' code_verifier' , code_verifier ) ;
106+ params . append ( " code_verifier" , code_verifier ) ;
106107 }
107108 const tokenResponse = await fetch ( `${ SCHEME } ://${ instanceURL } /oauth/token` , {
108- method : ' POST' ,
109+ method : " POST" ,
109110 headers : {
110- ' Content-Type' : ' application/x-www-form-urlencoded' ,
111+ " Content-Type" : " application/x-www-form-urlencoded" ,
111112 } ,
112113 body : params . toString ( ) ,
113114 } ) ;
@@ -130,17 +131,17 @@ export async function revokeAccessToken({
130131 } ) ;
131132
132133 const revokeResponse = await fetch ( `https://${ instanceURL } /oauth/revoke` , {
133- method : ' POST' ,
134+ method : " POST" ,
134135 headers : {
135- ' Content-Type' : ' application/x-www-form-urlencoded' ,
136+ " Content-Type" : " application/x-www-form-urlencoded" ,
136137 } ,
137138 body : params . toString ( ) ,
138139 keepalive : true ,
139140 } ) ;
140141
141142 return revokeResponse . ok ;
142143 } catch ( error ) {
143- console . erro ( ' Error revoking token' , error ) ;
144+ console . erro ( " Error revoking token" , error ) ;
144145 return false ;
145146 }
146147}
0 commit comments