mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Use URL literal instead of strings
This commit is contained in:
parent
99fac323c8
commit
76d1ccc859
50 changed files with 343 additions and 256 deletions
|
|
@ -86,7 +86,9 @@ export default (plugin: PluginType): void => {
|
|||
{
|
||||
id: issuer.id,
|
||||
name: issuer.name,
|
||||
icon: proxyUrl(issuer.icon) ?? undefined,
|
||||
icon: issuer.icon
|
||||
? proxyUrl(new URL(issuer.icon))
|
||||
: undefined,
|
||||
},
|
||||
200,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -114,7 +114,9 @@ export default (plugin: PluginType): void => {
|
|||
);
|
||||
}
|
||||
|
||||
const authServer = await oauthDiscoveryRequest(issuer.url);
|
||||
const authServer = await oauthDiscoveryRequest(
|
||||
new URL(issuer.url),
|
||||
);
|
||||
|
||||
const codeVerifier = generateRandomCodeVerifier();
|
||||
|
||||
|
|
@ -130,7 +132,7 @@ export default (plugin: PluginType): void => {
|
|||
crypto.getRandomValues(new Uint8Array(32)),
|
||||
).toString("base64"),
|
||||
name: "Versia",
|
||||
redirectUri,
|
||||
redirectUri: redirectUri.toString(),
|
||||
scopes: "openid profile email",
|
||||
secret: "",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,17 +20,15 @@ import {
|
|||
} from "oauth4webapi";
|
||||
|
||||
export const oauthDiscoveryRequest = (
|
||||
issuerUrl: string | URL,
|
||||
issuerUrl: URL,
|
||||
): Promise<AuthorizationServer> => {
|
||||
const issuerUrlurl = new URL(issuerUrl);
|
||||
|
||||
return discoveryRequest(issuerUrlurl, {
|
||||
return discoveryRequest(issuerUrl, {
|
||||
algorithm: "oidc",
|
||||
}).then((res) => processDiscoveryResponse(issuerUrlurl, res));
|
||||
}).then((res) => processDiscoveryResponse(issuerUrl, res));
|
||||
};
|
||||
|
||||
export const oauthRedirectUri = (baseUrl: string, issuer: string): string =>
|
||||
new URL(`/oauth/sso/${issuer}/callback`, baseUrl).toString();
|
||||
export const oauthRedirectUri = (baseUrl: URL, issuer: string): URL =>
|
||||
new URL(`/oauth/sso/${issuer}/callback`, baseUrl);
|
||||
|
||||
const getFlow = (
|
||||
flowId: string,
|
||||
|
|
@ -73,7 +71,7 @@ const getOIDCResponse = (
|
|||
authServer: AuthorizationServer,
|
||||
clientId: string,
|
||||
clientSecret: string,
|
||||
redirectUri: string,
|
||||
redirectUri: URL,
|
||||
codeVerifier: string,
|
||||
parameters: URLSearchParams,
|
||||
): Promise<Response> => {
|
||||
|
|
@ -84,7 +82,7 @@ const getOIDCResponse = (
|
|||
},
|
||||
ClientSecretPost(clientSecret),
|
||||
parameters,
|
||||
redirectUri,
|
||||
redirectUri.toString(),
|
||||
codeVerifier,
|
||||
);
|
||||
};
|
||||
|
|
@ -177,7 +175,7 @@ export const automaticOidcFlow = async (
|
|||
authServer,
|
||||
issuer.client_id,
|
||||
issuer.client_secret,
|
||||
redirectUrl.toString(),
|
||||
redirectUrl,
|
||||
flow.codeVerifier,
|
||||
parameters,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue