mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-02-19 01:55:48 -05:00
refactor: run formatter
This commit is contained in:
parent
522a041ca1
commit
1e96011793
5 changed files with 43 additions and 26 deletions
|
@ -120,7 +120,7 @@ export class AuthController {
|
||||||
})
|
})
|
||||||
@HttpCode(202)
|
@HttpCode(202)
|
||||||
async requestResetPassword(@Param("email") email: string) {
|
async requestResetPassword(@Param("email") email: string) {
|
||||||
this.authService.requestResetPassword(email);
|
await this.authService.requestResetPassword(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("resetPassword")
|
@Post("resetPassword")
|
||||||
|
@ -172,7 +172,9 @@ export class AuthController {
|
||||||
@Req() request: Request,
|
@Req() request: Request,
|
||||||
@Res({ passthrough: true }) response: Response,
|
@Res({ passthrough: true }) response: Response,
|
||||||
) {
|
) {
|
||||||
const redirectURI = await this.authService.signOut(request.cookies.access_token);
|
const redirectURI = await this.authService.signOut(
|
||||||
|
request.cookies.access_token,
|
||||||
|
);
|
||||||
|
|
||||||
const isSecure = this.config.get("general.appUrl").startsWith("https");
|
const isSecure = this.config.get("general.appUrl").startsWith("https");
|
||||||
response.cookie("access_token", "", {
|
response.cookie("access_token", "", {
|
||||||
|
|
|
@ -16,12 +16,12 @@ import * as moment from "moment";
|
||||||
import { ConfigService } from "src/config/config.service";
|
import { ConfigService } from "src/config/config.service";
|
||||||
import { EmailService } from "src/email/email.service";
|
import { EmailService } from "src/email/email.service";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
|
import { OAuthService } from "../oauth/oauth.service";
|
||||||
|
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
|
||||||
|
import { UserSevice } from "../user/user.service";
|
||||||
import { AuthRegisterDTO } from "./dto/authRegister.dto";
|
import { AuthRegisterDTO } from "./dto/authRegister.dto";
|
||||||
import { AuthSignInDTO } from "./dto/authSignIn.dto";
|
import { AuthSignInDTO } from "./dto/authSignIn.dto";
|
||||||
import { LdapService } from "./ldap.service";
|
import { LdapService } from "./ldap.service";
|
||||||
import { GenericOidcProvider } from "../oauth/provider/genericOidc.provider";
|
|
||||||
import { OAuthService } from "../oauth/oauth.service";
|
|
||||||
import { UserSevice } from "../user/user.service";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
|
@ -120,10 +120,7 @@ export class AuthService {
|
||||||
async generateToken(user: User, oauth?: { idToken?: string }) {
|
async generateToken(user: User, oauth?: { idToken?: string }) {
|
||||||
// TODO: Make all old loginTokens invalid when a new one is created
|
// TODO: Make all old loginTokens invalid when a new one is created
|
||||||
// Check if the user has TOTP enabled
|
// Check if the user has TOTP enabled
|
||||||
if (
|
if (user.totpVerified && !(oauth && this.config.get("oauth.ignoreTotp"))) {
|
||||||
user.totpVerified &&
|
|
||||||
!(oauth && this.config.get("oauth.ignoreTotp"))
|
|
||||||
) {
|
|
||||||
const loginToken = await this.createLoginToken(user.id);
|
const loginToken = await this.createLoginToken(user.id);
|
||||||
|
|
||||||
return { loginToken };
|
return { loginToken };
|
||||||
|
@ -163,7 +160,7 @@ export class AuthService {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.emailService.sendResetPasswordEmail(user.email, token);
|
this.emailService.sendResetPasswordEmail(user.email, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
async resetPassword(token: string, newPassword: string) {
|
async resetPassword(token: string, newPassword: string) {
|
||||||
|
@ -231,7 +228,10 @@ export class AuthService {
|
||||||
|
|
||||||
if (refreshTokenId) {
|
if (refreshTokenId) {
|
||||||
const oauthIDToken = await this.prisma.refreshToken
|
const oauthIDToken = await this.prisma.refreshToken
|
||||||
.findFirst({ select: { oauthIDToken: true }, where: { id: refreshTokenId } })
|
.findFirst({
|
||||||
|
select: { oauthIDToken: true },
|
||||||
|
where: { id: refreshTokenId },
|
||||||
|
})
|
||||||
.then((refreshToken) => refreshToken?.oauthIDToken)
|
.then((refreshToken) => refreshToken?.oauthIDToken)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
// Ignore error if refresh token doesn't exist
|
// Ignore error if refresh token doesn't exist
|
||||||
|
@ -249,16 +249,27 @@ export class AuthService {
|
||||||
const provider = this.oAuthService.availableProviders()[providerName];
|
const provider = this.oAuthService.availableProviders()[providerName];
|
||||||
let signOutFromProviderSupportedAndActivated = false;
|
let signOutFromProviderSupportedAndActivated = false;
|
||||||
try {
|
try {
|
||||||
signOutFromProviderSupportedAndActivated = this.config.get(`oauth.${providerName}-signOut`);
|
signOutFromProviderSupportedAndActivated = this.config.get(
|
||||||
|
`oauth.${providerName}-signOut`,
|
||||||
|
);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Ignore error if the provider is not supported or if the provider sign out is not activated
|
// Ignore error if the provider is not supported or if the provider sign out is not activated
|
||||||
}
|
}
|
||||||
if (provider instanceof GenericOidcProvider && signOutFromProviderSupportedAndActivated) {
|
if (
|
||||||
const configuration = await provider.getConfiguration();
|
provider instanceof GenericOidcProvider &&
|
||||||
if (configuration.frontchannel_logout_supported && URL.canParse(configuration.end_session_endpoint)) {
|
signOutFromProviderSupportedAndActivated
|
||||||
|
) {
|
||||||
|
const configuration = await provider.getConfiguration();
|
||||||
|
if (
|
||||||
|
configuration.frontchannel_logout_supported &&
|
||||||
|
URL.canParse(configuration.end_session_endpoint)
|
||||||
|
) {
|
||||||
const redirectURI = new URL(configuration.end_session_endpoint);
|
const redirectURI = new URL(configuration.end_session_endpoint);
|
||||||
redirectURI.searchParams.append("id_token_hint", idTokenHint);
|
redirectURI.searchParams.append("id_token_hint", idTokenHint);
|
||||||
redirectURI.searchParams.append("client_id", this.config.get(`oauth.${providerName}-clientId`));
|
redirectURI.searchParams.append(
|
||||||
|
"client_id",
|
||||||
|
this.config.get(`oauth.${providerName}-clientId`),
|
||||||
|
);
|
||||||
return redirectURI.toString();
|
return redirectURI.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ export class OAuthService {
|
||||||
private config: ConfigService,
|
private config: ConfigService,
|
||||||
@Inject(forwardRef(() => AuthService)) private auth: AuthService,
|
@Inject(forwardRef(() => AuthService)) private auth: AuthService,
|
||||||
@Inject("OAUTH_PLATFORMS") private platforms: string[],
|
@Inject("OAUTH_PLATFORMS") private platforms: string[],
|
||||||
@Inject("OAUTH_PROVIDERS") private oAuthProviders: Record<string, OAuthProvider<unknown>>,
|
@Inject("OAUTH_PROVIDERS")
|
||||||
|
private oAuthProviders: Record<string, OAuthProvider<unknown>>,
|
||||||
) {}
|
) {}
|
||||||
private readonly logger = new Logger(OAuthService.name);
|
private readonly logger = new Logger(OAuthService.name);
|
||||||
|
|
||||||
|
@ -30,13 +31,15 @@ export class OAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
availableProviders(): Record<string, OAuthProvider<unknown>> {
|
availableProviders(): Record<string, OAuthProvider<unknown>> {
|
||||||
return Object.fromEntries(Object.entries(this.oAuthProviders)
|
return Object.fromEntries(
|
||||||
.map(([providerName, provider]) => [
|
Object.entries(this.oAuthProviders)
|
||||||
[providerName, provider],
|
.map(([providerName, provider]) => [
|
||||||
this.config.get(`oauth.${providerName}-enabled`),
|
[providerName, provider],
|
||||||
])
|
this.config.get(`oauth.${providerName}-enabled`),
|
||||||
.filter(([_, enabled]) => enabled)
|
])
|
||||||
.map(([provider, _]) => provider));
|
.filter(([_, enabled]) => enabled)
|
||||||
|
.map(([provider, _]) => provider),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async status(user: User) {
|
async status(user: User) {
|
||||||
|
|
|
@ -31,7 +31,8 @@ const signUp = async (email: string, username: string, password: string) => {
|
||||||
const signOut = async () => {
|
const signOut = async () => {
|
||||||
const response = await api.post("/auth/signOut");
|
const response = await api.post("/auth/signOut");
|
||||||
|
|
||||||
if (URL.canParse(response.data?.redirectURI)) window.location.href = response.data.redirectURI;
|
if (URL.canParse(response.data?.redirectURI))
|
||||||
|
window.location.href = response.data.redirectURI;
|
||||||
else window.location.reload();
|
else window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue