-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
384 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
examples/passport-azure-ad/packages/server/src/decorators/OAuthBearer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
examples/passport-azure-ad/packages/server/src/protocols/BearerProtocol.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Req} from "@tsed/common"; | ||
import {OnVerify, PassportMiddleware, Protocol} from "@tsed/passport"; | ||
import {BearerStrategy, ITokenPayload} from "passport-azure-ad"; | ||
import {AuthService} from "../services/auth/AuthService"; | ||
|
||
@Protocol({ | ||
name: "azure-bearer", | ||
useStrategy: BearerStrategy | ||
}) | ||
export class BearerProtocol implements OnVerify { | ||
constructor(private authService: AuthService) { | ||
} | ||
|
||
$onVerify(@Req() req: Req, token: ITokenPayload) { | ||
// Verify is the right place to check given token and return UserInfo | ||
const {authService} = this; | ||
const {options = {}} = req.ctx.endpoint.get(PassportMiddleware) || {}; // retrieve options configured for the endpoint | ||
// check precondition and authenticate user by their token and given options | ||
try { | ||
const user = authService.verify(token, options); | ||
|
||
if (!user) { | ||
authService.add(token); | ||
req.ctx.logger.info({event: "BearerStrategy - token: ", token}); | ||
return token; | ||
} | ||
|
||
req.ctx.logger.info({event: "BearerStrategy - user: ", token}); | ||
return [user, token]; | ||
} catch (error) { | ||
req.ctx.logger.error({event: "BearerStrategy", token, error}); | ||
throw error; | ||
} | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
examples/passport-azure-ad/packages/server/src/protocols/BearerStrategy.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.