well-known controller

This commit is contained in:
Evert Prants 2022-12-04 11:29:20 +02:00
parent 64a675f36e
commit b62208ba47
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
4 changed files with 76 additions and 37 deletions

View File

@ -1,47 +1,10 @@
import { Controller, Get, Redirect } from '@nestjs/common';
import { ConfigurationService } from './modules/config/config.service';
@Controller()
export class AppController {
constructor(private config: ConfigurationService) {}
@Get()
@Redirect('/account/general')
getHello() {
return;
}
@Get('/.well-known/openid-configuration')
openidConfiguration() {
const base = this.config.get<string>('app.base_url');
return {
issuer: this.config.get('jwt.issuer'),
authorization_endpoint: `${base}/oauth2/authorize`,
token_endpoint: `${base}/oauth2/token`,
jwks_uri: `${base}/oauth2/jwks`,
userinfo_endpoint: `${base}/api/user`,
introspection_endpoint: `${base}/oauth2/introspect`,
response_types_supported: ['code', 'id_token'],
id_token_signing_alg_values_supported: [this.config.get('jwt.algorithm')],
subject_types_supported: ['public'],
scopes_supported: ['openid', 'profile', 'picture', 'email'],
claims_supported: [
'aud',
'exp',
'iat',
'iss',
'sub',
'name',
'preferred_username',
'nickname',
'profile',
'picture',
'updated_at',
'email',
'email_verified',
],
code_challenge_methods_supported: ['plain', 'S256'],
grant_types_supported: ['authorization_code', 'refresh_token'],
};
}
}

View File

@ -11,6 +11,7 @@ import { ConfigurationModule } from './modules/config/config.module';
import { JWTModule } from './modules/jwt/jwt.module';
import { SSRFrontEndModule } from './modules/ssr-front-end/ssr-front-end.module';
import { UtilityModule } from './modules/utility/utility.module';
import { WellKnownModule } from './modules/well-known/well-known.module';
@Module({
imports: [
@ -26,6 +27,7 @@ import { UtilityModule } from './modules/utility/utility.module';
UtilityModule,
JWTModule,
SSRFrontEndModule,
WellKnownModule,
ApiModule,
],
controllers: [AppController],

View File

@ -0,0 +1,64 @@
import { Controller, Get, Redirect, Res } from '@nestjs/common';
import { Response } from 'express';
import { ConfigurationService } from '../config/config.service';
@Controller({
path: '/.well-known/',
})
export class WellKnownController {
constructor(private config: ConfigurationService) {}
@Get('security.txt')
securityTXT(@Res({ passthrough: true }) res: Response) {
res.set('content-type', 'text/plain');
return `# If you would like to report a security issue
# you may report it to:
Contact: mailto:evert@lunasqu.ee
`;
}
@Get('dnt')
DNT() {
return { tracking: 'N' };
}
@Get('change-password')
@Redirect('/account/security')
changePassword() {
return;
}
@Get('openid-configuration')
openidConfiguration() {
const base = this.config.get<string>('app.base_url');
return {
issuer: this.config.get('jwt.issuer'),
authorization_endpoint: `${base}/oauth2/authorize`,
token_endpoint: `${base}/oauth2/token`,
jwks_uri: `${base}/oauth2/jwks`,
userinfo_endpoint: `${base}/api/user`,
introspection_endpoint: `${base}/oauth2/introspect`,
response_types_supported: ['code', 'id_token'],
id_token_signing_alg_values_supported: [this.config.get('jwt.algorithm')],
subject_types_supported: ['public'],
scopes_supported: ['openid', 'profile', 'picture', 'email'],
claims_supported: [
'aud',
'exp',
'iat',
'iss',
'sub',
'name',
'preferred_username',
'nickname',
'profile',
'picture',
'updated_at',
'email',
'email_verified',
],
code_challenge_methods_supported: ['plain', 'S256'],
grant_types_supported: ['authorization_code', 'refresh_token'],
};
}
}

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { ConfigurationModule } from '../config/config.module';
import { JWTModule } from '../jwt/jwt.module';
import { WellKnownController } from './well-known.controller';
@Module({
imports: [ConfigurationModule, JWTModule],
controllers: [WellKnownController],
})
export class WellKnownModule {}