kopia lustrzana https://github.com/cheeaun/phanpy
Set force_login if already has account from same instance
rodzic
cbf65628a3
commit
3ba97ad414
|
@ -1490,8 +1490,8 @@ msgid "Accounts…"
|
|||
msgstr ""
|
||||
|
||||
#: src/components/nav-menu.jsx:326
|
||||
#: src/pages/login.jsx:31
|
||||
#: src/pages/login.jsx:191
|
||||
#: src/pages/login.jsx:32
|
||||
#: src/pages/login.jsx:195
|
||||
#: src/pages/status.jsx:866
|
||||
#: src/pages/welcome.jsx:65
|
||||
msgid "Log in"
|
||||
|
@ -1926,7 +1926,7 @@ msgstr ""
|
|||
#: src/components/shortcuts-settings.jsx:75
|
||||
#: src/components/shortcuts-settings.jsx:84
|
||||
#: src/components/shortcuts-settings.jsx:122
|
||||
#: src/pages/login.jsx:195
|
||||
#: src/pages/login.jsx:199
|
||||
msgid "Instance"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2594,7 +2594,7 @@ msgstr "Login required."
|
|||
#: src/compose.jsx:91
|
||||
#: src/pages/annual-report.jsx:164
|
||||
#: src/pages/http-route.jsx:91
|
||||
#: src/pages/login.jsx:272
|
||||
#: src/pages/login.jsx:276
|
||||
msgid "Go home"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3307,32 +3307,32 @@ msgstr ""
|
|||
msgid "No lists yet."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:115
|
||||
#: src/pages/login.jsx:124
|
||||
#: src/pages/login.jsx:118
|
||||
#: src/pages/login.jsx:128
|
||||
msgid "Failed to register application"
|
||||
msgstr "Failed to register application"
|
||||
|
||||
#: src/pages/login.jsx:210
|
||||
#: src/pages/login.jsx:214
|
||||
msgid "instance domain"
|
||||
msgstr "instance domain"
|
||||
|
||||
#: src/pages/login.jsx:234
|
||||
#: src/pages/login.jsx:238
|
||||
msgid "e.g. “mastodon.social”"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:245
|
||||
#: src/pages/login.jsx:249
|
||||
msgid "Failed to log in. Please try again or try another instance."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:257
|
||||
#: src/pages/login.jsx:261
|
||||
msgid "Continue with {selectedInstanceText}"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:258
|
||||
#: src/pages/login.jsx:262
|
||||
msgid "Continue"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/login.jsx:266
|
||||
#: src/pages/login.jsx:270
|
||||
msgid "Don't have an account? Create one!"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import { supportsPKCE } from '../utils/oauth-pkce';
|
|||
import store from '../utils/store';
|
||||
import {
|
||||
getCredentialApplication,
|
||||
hasAccountInInstance,
|
||||
storeCredentialApplication,
|
||||
} from '../utils/store-utils';
|
||||
import useTitle from '../utils/useTitle';
|
||||
|
@ -103,11 +104,13 @@ function Login() {
|
|||
|
||||
const authPKCE = await supportsPKCE({ instanceURL });
|
||||
console.log({ authPKCE });
|
||||
const forceLogin = hasAccountInInstance(instanceURL);
|
||||
if (authPKCE) {
|
||||
if (client_id && client_secret) {
|
||||
const [url, verifier] = await getPKCEAuthorizationURL({
|
||||
instanceURL,
|
||||
client_id,
|
||||
forceLogin,
|
||||
});
|
||||
store.sessionCookie.set('codeVerifier', verifier);
|
||||
location.href = url;
|
||||
|
@ -119,6 +122,7 @@ function Login() {
|
|||
location.href = await getAuthorizationURL({
|
||||
instanceURL,
|
||||
client_id,
|
||||
forceLogin,
|
||||
});
|
||||
} else {
|
||||
alert(t`Failed to register application`);
|
||||
|
|
|
@ -45,7 +45,11 @@ export async function registerApplication({ instanceURL }) {
|
|||
return registrationJSON;
|
||||
}
|
||||
|
||||
export async function getPKCEAuthorizationURL({ instanceURL, client_id }) {
|
||||
export async function getPKCEAuthorizationURL({
|
||||
instanceURL,
|
||||
client_id,
|
||||
forceLogin = false,
|
||||
}) {
|
||||
const codeVerifier = verifier();
|
||||
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
||||
const params = new URLSearchParams({
|
||||
|
@ -56,11 +60,16 @@ export async function getPKCEAuthorizationURL({ instanceURL, client_id }) {
|
|||
response_type: 'code',
|
||||
scope: SCOPES,
|
||||
});
|
||||
if (forceLogin) params.append('force_login', true);
|
||||
const authorizationURL = `https://${instanceURL}/oauth/authorize?${params.toString()}`;
|
||||
return [authorizationURL, codeVerifier];
|
||||
}
|
||||
|
||||
export async function getAuthorizationURL({ instanceURL, client_id }) {
|
||||
export async function getAuthorizationURL({
|
||||
instanceURL,
|
||||
client_id,
|
||||
forceLogin = false,
|
||||
}) {
|
||||
const authorizationParams = new URLSearchParams({
|
||||
client_id,
|
||||
scope: SCOPES,
|
||||
|
@ -68,6 +77,7 @@ export async function getAuthorizationURL({ instanceURL, client_id }) {
|
|||
// redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
||||
response_type: 'code',
|
||||
});
|
||||
if (forceLogin) authorizationParams.append('force_login', true);
|
||||
const authorizationURL = `https://${instanceURL}/oauth/authorize?${authorizationParams.toString()}`;
|
||||
return authorizationURL;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ export function getAccountByInstance(instance) {
|
|||
return accounts.find((a) => a.instanceURL === instance);
|
||||
}
|
||||
|
||||
export function hasAccountInInstance(instance) {
|
||||
const accounts = store.local.getJSON('accounts') || [];
|
||||
return accounts.some((a) => a.instanceURL === instance);
|
||||
}
|
||||
|
||||
const standaloneMQ = window.matchMedia('(display-mode: standalone)');
|
||||
|
||||
export function getCurrentAccountID() {
|
||||
|
|
Ładowanie…
Reference in New Issue