Skip to content

Commit 2375a17

Browse files
committed
Updating to latest phanpy
1 parent 2372379 commit 2375a17

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/pages/login.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Login() {
7272
// WEB_DOMAIN vs LOCAL_DOMAIN negotiation time
7373
// https://docs.joinmastodon.org/admin/config/#web_domain
7474
try {
75-
const res = await fetch(`https://${instanceURL}/.well-known/host-meta`); // returns XML
75+
const res = await fetch(`${PHANPY_SCHEME}://${instanceURL}/.well-known/host-meta`); // returns XML
7676
const text = await res.text();
7777
// Parse XML
7878
const parser = new DOMParser();

src/utils/auth.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { generateCodeChallenge, verifier } from './oauth-pkce';
1+
import { generateCodeChallenge, verifier } from "./oauth-pkce";
22

33
const {
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

Comments
 (0)