-
Notifications
You must be signed in to change notification settings - Fork 29.9k
/
feathersjs__authentication-oauth2-tests.ts
91 lines (78 loc) · 2.21 KB
/
feathersjs__authentication-oauth2-tests.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import feathers, { Application } from '@feathersjs/feathers';
import feathersAuthenticationOAuth2, { Verifier, FeathersAuthenticationOAuth2Options } from '@feathersjs/authentication-oauth2';
import { RequestHandler, Response, NextFunction } from 'express';
import { Request } from 'express-serve-static-core';
import { Strategy } from 'passport';
import { Profile as GithubProfile } from 'passport-github';
import { Profile as FacebookProfile } from 'passport-facebook';
const app: Application = feathers().configure(feathersAuthenticationOAuth2());
class CustomVerifier extends Verifier {
constructor(app: Application, options: any = {}) {
super(app, options);
}
}
const handler: RequestHandler = (req: Request, res: Response, next: NextFunction) => { };
class someStrategy extends Strategy {
something = "foo";
}
/**
* Strongly Typed Verifier
*/
interface User {
name?: string;
email?: string;
facebookId?: string;
orSomeOtherProviderId?: string;
}
interface VerifierOptions extends FeathersAuthenticationOAuth2Options {
foo?: boolean;
}
type IProfileType = GithubProfile | FacebookProfile;
export default class TestVerifier extends Verifier<User, VerifierOptions, IProfileType> { }
const testVerifier = new TestVerifier(app, {
name: "test",
foo: false,
successRedirect: "foo",
failureRedirect: "bar",
service: 'Users',
Strategy: someStrategy,
passReqToCallback: false,
session: false
});
testVerifier._createEntity({
profile: {
id: "",
displayName: "",
birthday: "",
_raw: "",
_json: "",
provider: ""
},
accessToken: "",
refreshToken: ""
});
/**
* Options
*/
const coreOptions: FeathersAuthenticationOAuth2Options = {
name: "foo",
Strategy: someStrategy,
successRedirect: "foo",
failureRedirect: "foo",
service: "foo",
passReqToCallback: true,
session: true
};
const options: FeathersAuthenticationOAuth2Options<typeof TestVerifier> = {
...coreOptions,
idField: "foo",
path: "foo",
callbackPath: "foo",
callbackURL: "foo",
entity: "foo",
service: "foo",
handler,
errorHandler: handler,
formatter: handler,
Verifier: TestVerifier
};