Fix external login scopes

environments/review-fix-extern-otfjv5/deployments/2431
Alex Gleason 2023-01-25 16:32:59 -06:00
rodzic a68b794476
commit a4addf9aee
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 17 dodań i 9 usunięć

Wyświetl plik

@ -15,7 +15,7 @@ import sourceCode from 'soapbox/utils/code';
import { getWalletAndSign } from 'soapbox/utils/ethereum';
import { getFeatures } from 'soapbox/utils/features';
import { getQuirks } from 'soapbox/utils/quirks';
import { getScopes } from 'soapbox/utils/scopes';
import { getInstanceScopes } from 'soapbox/utils/scopes';
import { baseClient } from '../api';
@ -38,7 +38,7 @@ const fetchExternalInstance = (baseURL?: string) => {
};
const createExternalApp = (instance: Instance, baseURL?: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
(dispatch: AppDispatch, _getState: () => RootState) => {
// Mitra: skip creating the auth app
if (getQuirks(instance).noApps) return new Promise(f => f({}));
@ -46,15 +46,15 @@ const createExternalApp = (instance: Instance, baseURL?: string) =>
client_name: sourceCode.displayName,
redirect_uris: `${window.location.origin}/login/external`,
website: sourceCode.homepage,
scopes: getScopes(getState()),
scopes: getInstanceScopes(instance),
};
return dispatch(createApp(params, baseURL));
};
const externalAuthorize = (instance: Instance, baseURL: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const scopes = getScopes(getState());
(dispatch: AppDispatch, _getState: () => RootState) => {
const scopes = getInstanceScopes(instance);
return dispatch(createExternalApp(instance, baseURL)).then((app) => {
const { client_id, redirect_uri } = app as Record<string, string>;
@ -88,7 +88,7 @@ const externalEthereumLogin = (instance: Instance, baseURL?: string) =>
client_secret: client_secret,
password: signature as string,
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
scope: getScopes(getState()),
scope: getInstanceScopes(instance),
};
return dispatch(obtainOAuthToken(params, baseURL))

Wyświetl plik

@ -1,13 +1,14 @@
import { RootState } from 'soapbox/store';
import { PLEROMA, parseVersion } from './features';
import type { RootState } from 'soapbox/store';
import type { Instance } from 'soapbox/types/entities';
/**
* Get the OAuth scopes to use for login & signup.
* Mastodon will refuse scopes it doesn't know, so care is needed.
*/
const getScopes = (state: RootState) => {
const instance = state.instance;
const getInstanceScopes = (instance: Instance) => {
const v = parseVersion(instance.version);
switch (v.software) {
@ -18,6 +19,13 @@ const getScopes = (state: RootState) => {
}
};
/** Convenience function to get scopes from instance in store. */
const getScopes = (state: RootState) => {
return getInstanceScopes(state.instance);
};
export {
getInstanceScopes,
getScopes,
};