Début Oauth, la redirection fonctionne bien.

This commit is contained in:
batche
2022-11-02 11:14:37 +01:00
parent 3b24582ebc
commit 9a6ad5b328
20 changed files with 75 additions and 43 deletions

View File

@@ -14,11 +14,13 @@ const users_module_1 = require("./users/users.module");
const typeorm_1 = require("@nestjs/typeorm"); const typeorm_1 = require("@nestjs/typeorm");
const config_1 = require("@nestjs/config"); const config_1 = require("@nestjs/config");
const friendships_module_1 = require("./friendship/friendships.module"); const friendships_module_1 = require("./friendship/friendships.module");
const authentication_module_1 = require("./auth/42/authentication.module");
let AppModule = class AppModule { let AppModule = class AppModule {
}; };
AppModule = __decorate([ AppModule = __decorate([
(0, common_1.Module)({ (0, common_1.Module)({
imports: [users_module_1.UsersModule, imports: [users_module_1.UsersModule,
authentication_module_1.AuthenticationModule,
friendships_module_1.FriendshipsModule, friendships_module_1.FriendshipsModule,
config_1.ConfigModule.forRoot(), config_1.ConfigModule.forRoot(),
typeorm_1.TypeOrmModule.forRoot({ typeorm_1.TypeOrmModule.forRoot({

View File

@@ -1 +1 @@
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,+CAA2C;AAC3C,uDAAmD;AACnD,6CAAgD;AAChD,2CAA8C;AAC9C,wEAAoE;AAuB7D,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IApBrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,0BAAW;YACpB,sCAAiB;YACjB,qBAAY,CAAC,OAAO,EAAE;YACtB,uBAAa,CAAC,OAAO,CAAC;gBACrB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;gBAC/B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;gBACzC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;gBACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBACvC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBACvC,gBAAgB,EAAE,IAAI;gBAGtB,WAAW,EAAE,IAAI;aACjB,CAAC;SACJ;QACC,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;KACxB,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"} {"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qDAAiD;AACjD,+CAA2C;AAC3C,uDAAmD;AACnD,6CAAgD;AAChD,2CAA8C;AAC9C,wEAAoE;AACpE,2EAAuE;AAuBhE,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,SAAS;IArBrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,0BAAW;YACpB,4CAAoB;YACpB,sCAAiB;YACjB,qBAAY,CAAC,OAAO,EAAE;YACtB,uBAAa,CAAC,OAAO,CAAC;gBACrB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;gBAC/B,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;gBACzC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;gBACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBACvC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;gBACvC,gBAAgB,EAAE,IAAI;gBAGtB,WAAW,EAAE,IAAI;aACjB,CAAC;SACJ;QACC,WAAW,EAAE,CAAC,8BAAa,CAAC;QAC5B,SAAS,EAAE,CAAC,wBAAU,CAAC;KACxB,CAAC;GACW,SAAS,CAAG;AAAZ,8BAAS"}

View File

@@ -1,6 +1,10 @@
import { AuthenticationService } from './authentication.service';
import { Response } from 'express'; import { Response } from 'express';
export declare class AuthenticationController { export declare class AuthenticationController {
login(): string; private readonly authService;
constructor(authService: AuthenticationService);
hello(): string;
login(res: Response): Response<any, Record<string, any>>;
redirect(res: Response): void; redirect(res: Response): void;
status(): string; status(): string;
logout(): string; logout(): string;

View File

@@ -14,12 +14,22 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationController = void 0; exports.AuthenticationController = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const guards_1 = require("./guards/guards");
const authentication_service_1 = require("./authentication.service");
let AuthenticationController = class AuthenticationController { let AuthenticationController = class AuthenticationController {
login() { constructor(authService) {
return 'login'; this.authService = authService;
}
hello() {
console.log('AUTHENTICATION CONTROLLER');
return 'hello';
}
login(res) {
return res.sendStatus(200);
} }
redirect(res) { redirect(res) {
res.send(200); console.log(`Redirection performed`);
res.sendStatus(200);
} }
status() { status() {
return 'status'; return 'status';
@@ -29,10 +39,18 @@ let AuthenticationController = class AuthenticationController {
} }
}; };
__decorate([ __decorate([
(0, common_1.Get)('login'), (0, common_1.Get)(),
__metadata("design:type", Function), __metadata("design:type", Function),
__metadata("design:paramtypes", []), __metadata("design:paramtypes", []),
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], AuthenticationController.prototype, "hello", null);
__decorate([
(0, common_1.Get)('login'),
(0, common_1.UseGuards)(guards_1.FortyTwoAuthGuard),
__param(0, (0, common_1.Res)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], AuthenticationController.prototype, "login", null); ], AuthenticationController.prototype, "login", null);
__decorate([ __decorate([
(0, common_1.Get)('redirect'), (0, common_1.Get)('redirect'),
@@ -54,7 +72,8 @@ __decorate([
__metadata("design:returntype", void 0) __metadata("design:returntype", void 0)
], AuthenticationController.prototype, "logout", null); ], AuthenticationController.prototype, "logout", null);
AuthenticationController = __decorate([ AuthenticationController = __decorate([
(0, common_1.Controller)('auth') (0, common_1.Controller)('auth'),
__metadata("design:paramtypes", [authentication_service_1.AuthenticationService])
], AuthenticationController); ], AuthenticationController);
exports.AuthenticationController = AuthenticationController; exports.AuthenticationController = AuthenticationController;
//# sourceMappingURL=authentication.controller.js.map //# sourceMappingURL=authentication.controller.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"authentication.controller.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAsD;AAI/C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAQpC,KAAK;QACJ,OAAO,OAAO,CAAC;IAChB,CAAC;IAQD,QAAQ,CAAQ,GAAa;QAC5B,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAQD,MAAM;QACL,OAAO,QAAQ,CAAC;IACjB,CAAC;IAOD,MAAM;QACL,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD,CAAA;AAjCA;IAAC,IAAA,YAAG,EAAC,OAAO,CAAC;;;;qDAGZ;AAOD;IAAC,IAAA,YAAG,EAAC,UAAU,CAAC;IACN,WAAA,IAAA,YAAG,GAAE,CAAA;;;;wDAEd;AAOD;IAAC,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;sDAGb;AAMD;IAAC,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;sDAGb;AAvCW,wBAAwB;IADpC,IAAA,mBAAU,EAAC,MAAM,CAAC;GACN,wBAAwB,CAwCpC;AAxCY,4DAAwB"} {"version":3,"file":"authentication.controller.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAiE;AACjE,4CAAoD;AACpD,qEAAiE;AAI1D,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAEpC,YAA6B,WAAkC;QAAlC,gBAAW,GAAX,WAAW,CAAuB;IAAG,CAAC;IAInE,KAAK;QACJ,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC;IAChB,CAAC;IAOD,KAAK,CAAQ,GAAa;QACzB,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAQD,QAAQ,CAAQ,GAAa;QAC5B,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACrC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAQD,MAAM;QACL,OAAO,QAAQ,CAAC;IACjB,CAAC;IAOD,MAAM;QACL,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD,CAAA;AA5CA;IAAC,IAAA,YAAG,GAAE;;;;qDAIL;AAKD;IAAC,IAAA,YAAG,EAAC,OAAO,CAAC;IACZ,IAAA,kBAAS,EAAC,0BAAiB,CAAC;IACtB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;qDAEX;AAOD;IAAC,IAAA,YAAG,EAAC,UAAU,CAAC;IACN,WAAA,IAAA,YAAG,GAAE,CAAA;;;;wDAGd;AAOD;IAAC,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;sDAGb;AAMD;IAAC,IAAA,YAAG,EAAC,QAAQ,CAAC;;;;sDAGb;AAhDW,wBAAwB;IADpC,IAAA,mBAAU,EAAC,MAAM,CAAC;qCAGwB,8CAAqB;GAFnD,wBAAwB,CAiDpC;AAjDY,4DAAwB"}

View File

@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationModule = void 0; exports.AuthenticationModule = void 0;
const common_1 = require("@nestjs/common"); const common_1 = require("@nestjs/common");
const users_module_1 = require("../../users/users.module"); const users_module_1 = require("../../users/users.module");
const authentication_controller_1 = require("./authentication.controller");
const authentication_service_1 = require("./authentication.service"); const authentication_service_1 = require("./authentication.service");
const strategy_1 = require("./strategy/strategy"); const strategy_1 = require("./strategy/strategy");
let AuthenticationModule = class AuthenticationModule { let AuthenticationModule = class AuthenticationModule {
@@ -17,6 +18,8 @@ AuthenticationModule = __decorate([
(0, common_1.Module)({ (0, common_1.Module)({
imports: [users_module_1.UsersModule], imports: [users_module_1.UsersModule],
providers: [authentication_service_1.AuthenticationService, strategy_1.FortyTwoStrategy], providers: [authentication_service_1.AuthenticationService, strategy_1.FortyTwoStrategy],
exports: [authentication_service_1.AuthenticationService],
controllers: [authentication_controller_1.AuthenticationController],
}) })
], AuthenticationModule); ], AuthenticationModule);
exports.AuthenticationModule = AuthenticationModule; exports.AuthenticationModule = AuthenticationModule;

View File

@@ -1 +1 @@
{"version":3,"file":"authentication.module.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAqD;AACrD,qEAAiE;AACjE,kDAAuD;AAMhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IAJhC,IAAA,eAAM,EAAC;QACL,OAAO,EAAE,CAAC,0BAAW,CAAC;QACtB,SAAS,EAAE,CAAC,8CAAqB,EAAE,2BAAgB,CAAC;KACtD,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB"} {"version":3,"file":"authentication.module.js","sourceRoot":"","sources":["../../../src/auth/42/authentication.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAqD;AACrD,2EAAuE;AACvE,qEAAiE;AACjE,kDAAuD;AAQhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAAG,CAAA;AAAvB,oBAAoB;IANhC,IAAA,eAAM,EAAC;QACL,OAAO,EAAE,CAAC,0BAAW,CAAC;QACtB,SAAS,EAAE,CAAC,8CAAqB,EAAE,2BAAgB,CAAC;QACpD,OAAO,EAAE,CAAC,8CAAqB,CAAC;QAChC,WAAW,EAAE,CAAC,oDAAwB,CAAC;KACzC,CAAC;GACW,oBAAoB,CAAG;AAAvB,oDAAoB"}

View File

@@ -1 +1 @@
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../src/auth/42/guards/guards.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,+CAA6C;AAGtC,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,IAAA,oBAAS,EAAC,IAAI,CAAC;IACpD,KAAK,CAAC,WAAW,CAAC,OAAyB;QAC5C,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAY,CAAC;QAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,QAAQ,CAAC;IACf,CAAC;CACF,CAAA;AARY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAQ7B;AARY,8CAAiB"} {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../src/auth/42/guards/guards.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,+CAA6C;AAGtC,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,IAAA,oBAAS,EAAC,IAAI,CAAC;IACrD,KAAK,CAAC,WAAW,CAAC,OAAyB;QAC1C,MAAM,QAAQ,GAAG,CAAC,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAY,CAAC;QAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD,CAAA;AARY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAQ7B;AARY,8CAAiB"}

View File

@@ -25,6 +25,8 @@ let FortyTwoStrategy = class FortyTwoStrategy extends (0, passport_1.PassportStr
this.authenticationService = authenticationService; this.authenticationService = authenticationService;
} }
async validate(accessToken, refreshToken, profile, callbackURL) { async validate(accessToken, refreshToken, profile, callbackURL) {
const { id, username, displayName, photos } = profile;
console.log(profile);
} }
}; };
FortyTwoStrategy = __decorate([ FortyTwoStrategy = __decorate([

View File

@@ -1 +1 @@
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../../src/auth/42/strategy/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoD;AACpD,+CAAoD;AACpD,2CAA4C;AAC5C,sEAAkE;AAG3D,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,IAAA,2BAAgB,EAAC,cAAQ,EAAE,IAAI,CAAC;IACnE,YAA6B,qBAA4C;QAC3E,KAAK,CAAC;YACJ,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;YACxC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;YAChD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,KAAK,EAAE,CAAC,QAAQ,CAAC;SAClB,CAAC,CAAC;QAN4B,0BAAqB,GAArB,qBAAqB,CAAuB;IAO1E,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,WAAmB,EAAE,YAAoB,EAAE,OAAgB,EAAE,WAAmB;IAE/F,CAAC;CACF,CAAA;AAbY,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE0C,8CAAqB;GAD/D,gBAAgB,CAa5B;AAbY,4CAAgB"} {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../../src/auth/42/strategy/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoD;AACpD,+CAAoD;AACpD,2CAA4C;AAC5C,sEAAkE;AAG3D,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,IAAA,2BAAgB,EAAC,cAAQ,EAAE,IAAI,CAAC;IACnE,YAA6B,qBAA4C;QAC3E,KAAK,CAAC;YACJ,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;YACxC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;YAChD,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,KAAK,EAAE,CAAC,QAAQ,CAAC;SAClB,CAAC,CAAC;QAN4B,0BAAqB,GAArB,qBAAqB,CAAuB;IAO1E,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,WAAmB,EAAE,YAAoB,EAAE,OAAgB,EAAE,WAAmB;QAChG,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;CACF,CAAA;AAdY,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAE0C,8CAAqB;GAD/D,gBAAgB,CAc5B;AAdY,4CAAgB"}

View File

@@ -13,8 +13,9 @@ async function bootstrap() {
enableImplicitConversion: true, enableImplicitConversion: true,
}, },
})); }));
const port = process.env.PORT || 3000;
app.setGlobalPrefix('api/v2'); app.setGlobalPrefix('api/v2');
await app.listen(3000); await app.listen(port, () => { console.log(`Listening on port ${port}`); });
} }
bootstrap(); bootstrap();
//# sourceMappingURL=main.js.map //# sourceMappingURL=main.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,2CAAgD;AAChD,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IAEtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAGhD,GAAG,CAAC,cAAc,CACnB,IAAI,uBAAc,CAAC;QAElB,SAAS,EAAE,IAAI;QAEf,oBAAoB,EAAE,IAAI;QAE1B,SAAS,EAAE,IAAI;QACf,gBAAgB,EAAE;YACjB,wBAAwB,EAAE,IAAI;SAC9B;KACD,CAAC,CACA,CAAC;IACF,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AACD,SAAS,EAAE,CAAC"} {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,uCAA2C;AAC3C,2CAAgD;AAChD,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IAEtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAGhD,GAAG,CAAC,cAAc,CACnB,IAAI,uBAAc,CAAC;QAElB,SAAS,EAAE,IAAI;QAEf,oBAAoB,EAAE,IAAI;QAE1B,SAAS,EAAE,IAAI;QACf,gBAAgB,EAAE;YACjB,wBAAwB,EAAE,IAAI;SAC9B;KACD,CAAC,CACA,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;IACtC,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AACD,SAAS,EAAE,CAAC"}

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,7 @@ import { AuthenticationModule } from './auth/42/authentication.module';
@Module({ @Module({
imports: [UsersModule, imports: [UsersModule,
AuthenticationModule,
FriendshipsModule, FriendshipsModule,
ConfigModule.forRoot(), ConfigModule.forRoot(),
TypeOrmModule.forRoot({ TypeOrmModule.forRoot({

View File

@@ -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'; import { Response } from 'express';
@Controller('auth') @Controller('auth')
export class AuthenticationController { export class AuthenticationController {
constructor(private readonly authService: AuthenticationService) {}
@Get()
hello() {
console.log('AUTHENTICATION CONTROLLER');
return 'hello';
}
/** /**
* GET /api/v2/auth/login * GET /api/v2/auth/login
* Route pour l'autentification des utilisateurs * Route pour l'autentification des utilisateurs
*/ */
@Get('login') @Get('login')
login() { @UseGuards(FortyTwoAuthGuard)
return 'login'; login(@Res() res: Response) {
return res.sendStatus(200);
} }
/** /**
@@ -21,7 +31,8 @@ export class AuthenticationController {
*/ */
@Get('redirect') @Get('redirect')
redirect(@Res() res: Response) { redirect(@Res() res: Response) {
res.send(200); console.log(`Redirection performed`);
res.sendStatus(200);
} }
/** /**

View File

@@ -1,10 +1,13 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { UsersModule } from 'src/users/users.module'; import { UsersModule } from 'src/users/users.module';
import { AuthenticationController } from './authentication.controller';
import { AuthenticationService } from './authentication.service'; import { AuthenticationService } from './authentication.service';
import { FortyTwoStrategy } from './strategy/strategy'; import { FortyTwoStrategy } from './strategy/strategy';
@Module({ @Module({
imports: [UsersModule], imports: [UsersModule],
providers: [AuthenticationService, FortyTwoStrategy], providers: [AuthenticationService, FortyTwoStrategy],
exports: [AuthenticationService],
controllers: [AuthenticationController],
}) })
export class AuthenticationModule {} export class AuthenticationModule {}

View File

@@ -3,12 +3,12 @@ import { AuthGuard } from "@nestjs/passport";
@Injectable() @Injectable()
export class FortyTwoAuthGuard extends AuthGuard('42') { export class FortyTwoAuthGuard extends AuthGuard('42') {
async canActivate(context: ExecutionContext): Promise<any> { async canActivate(context: ExecutionContext): Promise<any> {
const activate = (await super.canActivate(context)) as boolean; const activate = (await super.canActivate(context)) as boolean;
const request = context.switchToHttp().getRequest(); const request = context.switchToHttp().getRequest();
console.log(request.user); console.log(request.user);
await super.logIn(request); await super.logIn(request);
return activate; return activate;
} }
} }

View File

@@ -15,6 +15,7 @@ export class FortyTwoStrategy extends PassportStrategy(Strategy, "42") {
} }
async validate(accessToken: string, refreshToken: string, profile: Profile, callbackURL: string) { async validate(accessToken: string, refreshToken: string, profile: Profile, callbackURL: string) {
const { id, username, displayName, photos } = profile;
console.log(profile);
} }
} }

View File

@@ -20,7 +20,8 @@ async function bootstrap() {
}, },
}), }),
); );
const port = process.env.PORT || 3000;
app.setGlobalPrefix('api/v2'); app.setGlobalPrefix('api/v2');
await app.listen(3000); await app.listen(port, () => { console.log(`Listening on port ${port}`); });
} }
bootstrap(); bootstrap();

View File

@@ -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,
},
],
},
];