UNPKG

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