-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
OAuthBearer.ts
executable file
·29 lines (27 loc) · 996 Bytes
/
OAuthBearer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {AuthOptions, UseAuth, UseBefore} from "@tsed/common";
import {applyDecorators} from "@tsed/core";
import {Operation, Responses, Security} from "@tsed/swagger";
import * as Passport from "passport";
import {OAuthBearerOptions} from "../protocols/BearerStrategy";
import {OAuthHead} from "./OAuthHead";
export function OAuthBearer(options: any = {}): Function {
return applyDecorators(
AuthOptions(OAuthBearerOptions as any, options), // Add this to store all options and retrieve it in verify function
UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),
// Metadata for swagger
Security("oauth", ...(options.scopes || [])),
Operation({
"parameters": [
{
"in": "header",
"name": "Authorization",
"type": "string",
"required": true
}
]
}),
Responses(401, {description: "Unauthorized"}),
Responses(403, {description: "Forbidden"}),
OAuthHead()
);
}