1 | /**
|
2 | * A callback function that consumes the context.
|
3 | */
|
4 | interface ContextConsumer { (context): void }
|
5 |
|
6 | /**
|
7 | * In the most cases, the protocol by itself can resolve
|
8 | * the authentication context. If so, it is a Mountable protocol.
|
9 | * Which can mount into the transport layer and populate the context.
|
10 | *
|
11 | */
|
12 | export interface Mountable {
|
13 | mount(consumer: ContextConsumer): any;
|
14 | }
|
15 |
|
16 | /**
|
17 | * A Service that can load the Credential from a give environment.
|
18 | * That environment so-called as the Authentication Context.
|
19 | */
|
20 | export interface Protocol {
|
21 |
|
22 | /**
|
23 | * Load (resolve) the credential
|
24 | *
|
25 | * @param context
|
26 | */
|
27 | resolve(context: Object): Promise<Credential>;
|
28 | }
|
29 |
|
30 | /**
|
31 | * The service that will find an Identity satisfied the given Credential.
|
32 | */
|
33 | export interface IdentityProvider {
|
34 |
|
35 | /**
|
36 | *
|
37 | * Providing the identity against the given credential.
|
38 | *
|
39 | * @param credential
|
40 | */
|
41 | provide(credential: Credential): Promise<Identity>;
|
42 | }
|
43 |
|
44 | /**
|
45 | * A piece of information that can be used for authenticating
|
46 | */
|
47 | export interface Credential {
|
48 |
|
49 | }
|
50 |
|
51 | /**
|
52 | * A piece of information that can be used for identifying
|
53 | * a resource.
|
54 | */
|
55 | export interface Identity {
|
56 |
|
57 | }
|
58 |
|
59 | /**
|
60 | * A service for verifying the an oauth2 state
|
61 | */
|
62 | export interface StateVerifier {
|
63 |
|
64 | /**
|
65 | * Generates the state when the Protocol call the authorize request.
|
66 | */
|
67 | makeState(): Promise<string>;
|
68 |
|
69 | /**
|
70 | * Determine if the state responded from the OAuth2 server is valid.
|
71 | *
|
72 | * @param stateFromOAuth2Server
|
73 | */
|
74 | verify(stateFromOAuth2Server): Promise<boolean>
|
75 | }
|