kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Actually do import the token into the auth app, fix applicationSchema and authAppSchema
rodzic
ae546db8f0
commit
09f813403f
|
@ -15,6 +15,7 @@ import {
|
||||||
SWITCH_ACCOUNT,
|
SWITCH_ACCOUNT,
|
||||||
VERIFY_CREDENTIALS_SUCCESS,
|
VERIFY_CREDENTIALS_SUCCESS,
|
||||||
VERIFY_CREDENTIALS_FAIL,
|
VERIFY_CREDENTIALS_FAIL,
|
||||||
|
AUTH_APP_AUTHORIZED,
|
||||||
} from '../actions/auth';
|
} from '../actions/auth';
|
||||||
import { ME_FETCH_SKIP } from '../actions/me';
|
import { ME_FETCH_SKIP } from '../actions/me';
|
||||||
|
|
||||||
|
@ -143,6 +144,18 @@ function reducer(state: SoapboxAuth, action: UnknownAction): SoapboxAuth {
|
||||||
const result = applicationSchema.safeParse(action.app);
|
const result = applicationSchema.safeParse(action.app);
|
||||||
return result.success ? importApplication(state, result.data) : state;
|
return result.success ? importApplication(state, result.data) : state;
|
||||||
}
|
}
|
||||||
|
case AUTH_APP_AUTHORIZED: {
|
||||||
|
const result = tokenSchema.safeParse(action.token);
|
||||||
|
if (result.success) {
|
||||||
|
return produce(state, draft => {
|
||||||
|
if (draft.app) {
|
||||||
|
draft.app.access_token = result.data.access_token;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
case AUTH_LOGGED_IN: {
|
case AUTH_LOGGED_IN: {
|
||||||
const result = tokenSchema.safeParse(action.token);
|
const result = tokenSchema.safeParse(action.token);
|
||||||
return result.success ? importToken(state, result.data) : state;
|
return result.success ? importToken(state, result.data) : state;
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const applicationSchema = z.object({
|
const applicationSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string().catch(''),
|
||||||
website: z.string().url().nullable().catch(null),
|
website: z.string().url().nullable().catch(null),
|
||||||
scopes: z.string().array().catch([]),
|
scopes: z.string().array().catch([]),
|
||||||
redirect_uris: z.string().url().array().optional().catch(undefined),
|
redirect_uris: z.string().url().array().optional().catch(undefined),
|
||||||
redirect_uri: z.string().url().optional().catch(undefined),
|
redirect_uri: z.string().url().optional().catch(undefined),
|
||||||
|
client_id: z.string().optional().catch(undefined),
|
||||||
|
client_secret: z.string().optional().catch(undefined),
|
||||||
|
client_secret_expires_at: z.number().optional().catch(0),
|
||||||
}).transform((app) => {
|
}).transform((app) => {
|
||||||
const { name, website, scopes, redirect_uris, redirect_uri } = app;
|
const { redirect_uris, redirect_uri, ...rest } = app;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
...rest,
|
||||||
website,
|
|
||||||
scopes,
|
|
||||||
redirect_uris: redirect_uris || (redirect_uri ? [redirect_uri] : []),
|
redirect_uris: redirect_uris || (redirect_uri ? [redirect_uri] : []),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,8 +9,14 @@ const authUserSchema = z.object({
|
||||||
url: z.string().url(),
|
url: z.string().url(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const authAppSchema = applicationSchema.and(
|
||||||
|
z.object({
|
||||||
|
access_token: z.string().optional().catch(undefined),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const soapboxAuthSchema = z.object({
|
const soapboxAuthSchema = z.object({
|
||||||
app: applicationSchema.optional(),
|
app: authAppSchema.optional(),
|
||||||
tokens: z.record(z.string(), tokenSchema),
|
tokens: z.record(z.string(), tokenSchema),
|
||||||
users: z.record(z.string(), authUserSchema),
|
users: z.record(z.string(), authUserSchema),
|
||||||
me: z.string().url().optional(),
|
me: z.string().url().optional(),
|
||||||
|
|
|
@ -5,6 +5,8 @@ const tokenSchema = z.object({
|
||||||
token_type: z.string(),
|
token_type: z.string(),
|
||||||
scope: z.string(),
|
scope: z.string(),
|
||||||
created_at: z.number(),
|
created_at: z.number(),
|
||||||
|
id: z.coerce.string().optional().catch(undefined), // Pleroma (primary key)
|
||||||
|
me: z.string().url().optional().catch(undefined), // Pleroma (ActivityPub ID of user)
|
||||||
});
|
});
|
||||||
|
|
||||||
type Token = z.infer<typeof tokenSchema>;
|
type Token = z.infer<typeof tokenSchema>;
|
||||||
|
|
Ładowanie…
Reference in New Issue