1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-06-30 14:40:10 +02:00

fix(oauth): fix wrong redirectUri in oidc after change appUrl (#296)

This commit is contained in:
Qing Fu 2023-10-23 03:20:50 +08:00 committed by GitHub
parent e89e313712
commit 119b1ec840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,6 @@ import { OAuthProvider, OAuthToken } from "./oauthProvider.interface";
import { OAuthSignInDto } from "../dto/oauthSignIn.dto";
export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
protected redirectUri: string;
protected discoveryUri: string;
private configuration: OidcConfigurationCache;
private jwk: OidcJwkCache;
@ -22,9 +21,6 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
protected cache: Cache,
) {
this.discoveryUri = this.getDiscoveryUri();
this.redirectUri = `${this.config.get(
"general.appUrl",
)}/api/oauth/callback/${this.name}`;
this.config.addListener("update", (key: string, _: unknown) => {
if (this.keyOfConfigUpdateEvents.includes(key)) {
this.deinit();
@ -33,6 +29,12 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
});
}
protected getRedirectUri(): string {
return `${this.config.get("general.appUrl")}/api/oauth/callback/${
this.name
}`;
}
async getConfiguration(): Promise<OidcConfiguration> {
if (!this.configuration || this.configuration.expires < Date.now()) {
await this.fetchConfiguration();
@ -65,7 +67,7 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
client_id: this.config.get(`oauth.${this.name}-clientId`),
response_type: "code",
scope: "openid profile email",
redirect_uri: this.redirectUri,
redirect_uri: this.getRedirectUri(),
state,
nonce,
}).toString()
@ -85,7 +87,7 @@ export abstract class GenericOidcProvider implements OAuthProvider<OidcToken> {
client_secret: this.config.get(`oauth.${this.name}-clientSecret`),
grant_type: "authorization_code",
code: query.code,
redirect_uri: this.redirectUri,
redirect_uri: this.getRedirectUri(),
}).toString(),
});
const token: OidcToken = await res.json();