Début Oauth, la redirection fonctionne bien.
This commit is contained in:
@@ -9,6 +9,7 @@ import { AuthenticationModule } from './auth/42/authentication.module';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule,
|
||||
AuthenticationModule,
|
||||
FriendshipsModule,
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forRoot({
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
import { Controller, Get, Res } from '@nestjs/common';
|
||||
import { Controller, Get, Res, UseGuards } from '@nestjs/common';
|
||||
import { FortyTwoAuthGuard } from './guards/guards';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { Response } from 'express';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthenticationController {
|
||||
|
||||
constructor(private readonly authService: AuthenticationService) {}
|
||||
|
||||
|
||||
@Get()
|
||||
hello() {
|
||||
console.log('AUTHENTICATION CONTROLLER');
|
||||
return 'hello';
|
||||
}
|
||||
/**
|
||||
* GET /api/v2/auth/login
|
||||
* Route pour l'autentification des utilisateurs
|
||||
*/
|
||||
@Get('login')
|
||||
login() {
|
||||
return 'login';
|
||||
@UseGuards(FortyTwoAuthGuard)
|
||||
login(@Res() res: Response) {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,7 +31,8 @@ export class AuthenticationController {
|
||||
*/
|
||||
@Get('redirect')
|
||||
redirect(@Res() res: Response) {
|
||||
res.send(200);
|
||||
console.log(`Redirection performed`);
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersModule } from 'src/users/users.module';
|
||||
import { AuthenticationController } from './authentication.controller';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { FortyTwoStrategy } from './strategy/strategy';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule],
|
||||
providers: [AuthenticationService, FortyTwoStrategy],
|
||||
exports: [AuthenticationService],
|
||||
controllers: [AuthenticationController],
|
||||
})
|
||||
export class AuthenticationModule {}
|
||||
|
||||
@@ -3,12 +3,12 @@ import { AuthGuard } from "@nestjs/passport";
|
||||
|
||||
@Injectable()
|
||||
export class FortyTwoAuthGuard extends AuthGuard('42') {
|
||||
async canActivate(context: ExecutionContext): Promise<any> {
|
||||
const activate = (await super.canActivate(context)) as boolean;
|
||||
const request = context.switchToHttp().getRequest();
|
||||
console.log(request.user);
|
||||
await super.logIn(request);
|
||||
return activate;
|
||||
}
|
||||
async canActivate(context: ExecutionContext): Promise<any> {
|
||||
const activate = (await super.canActivate(context)) as boolean;
|
||||
const request = context.switchToHttp().getRequest();
|
||||
console.log(request.user);
|
||||
await super.logIn(request);
|
||||
return activate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ export class FortyTwoStrategy extends PassportStrategy(Strategy, "42") {
|
||||
}
|
||||
|
||||
async validate(accessToken: string, refreshToken: string, profile: Profile, callbackURL: string) {
|
||||
|
||||
const { id, username, displayName, photos } = profile;
|
||||
console.log(profile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ async function bootstrap() {
|
||||
},
|
||||
}),
|
||||
);
|
||||
const port = process.env.PORT || 3000;
|
||||
app.setGlobalPrefix('api/v2');
|
||||
await app.listen(3000);
|
||||
await app.listen(port, () => { console.log(`Listening on port ${port}`); });
|
||||
}
|
||||
bootstrap();
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Routes } from "@nestjs/core";
|
||||
import { FriendshipsModule } from "src/friendship/friendships.module";
|
||||
import { UsersModule } from "src/users/users.module";
|
||||
|
||||
export const routesForUsers: Routes = [
|
||||
{
|
||||
path: '/users',
|
||||
module: UsersModule,
|
||||
children: [
|
||||
{
|
||||
path: '/:userId/mycontacts',
|
||||
module: FriendshipsModule,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user