1 | /**
|
2 | * This file is part of the @egodigital/egoose distribution.
|
3 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
4 | *
|
5 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
6 | * it under the terms of the GNU Lesser General Public License as
|
7 | * published by the Free Software Foundation, version 3.
|
8 | *
|
9 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 | * Lesser General Public License for more details.
|
13 | *
|
14 | * You should have received a copy of the GNU Lesser General Public License
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | */
|
17 | import * as express from 'express';
|
18 | /**
|
19 | * Data from 'https://graph.microsoft.com/v1.0/me'.
|
20 | */
|
21 | export interface MicrosoftMe {
|
22 | /**
|
23 | * The display name.
|
24 | */
|
25 | "displayName"?: string;
|
26 | /**
|
27 | * The given name.
|
28 | */
|
29 | "givenName"?: string;
|
30 | /**
|
31 | * The ID.
|
32 | */
|
33 | "id": string;
|
34 | /**
|
35 | * The mail address.
|
36 | */
|
37 | "mail"?: string;
|
38 | /**
|
39 | * The surname.
|
40 | */
|
41 | "surname"?: string;
|
42 | /**
|
43 | * The user's principal name.
|
44 | */
|
45 | "userPrincipalName"?: string;
|
46 | }
|
47 | /**
|
48 | * Data for a Microsoft Access token.
|
49 | */
|
50 | export interface MicrosoftOAuthAccessToken {
|
51 | /**
|
52 | * The token.
|
53 | */
|
54 | "access_token": string;
|
55 | /**
|
56 | * The time, in seconds, the token expires in.
|
57 | */
|
58 | "expires_in": string;
|
59 | /**
|
60 | * The refresh token.
|
61 | */
|
62 | "refresh_token": string;
|
63 | /**
|
64 | * The scope.
|
65 | */
|
66 | "scope": string;
|
67 | /**
|
68 | * The type, like "Bearer".
|
69 | */
|
70 | "token_type": string;
|
71 | }
|
72 | /**
|
73 | * Options for 'registerForMicrosoftOAuth()' function.
|
74 | */
|
75 | export interface RegisterForMicrosoftOAuthOptions {
|
76 | /**
|
77 | * Is invoked, when an access token has been received.
|
78 | *
|
79 | * @param {MicrosoftOAuthAccessToken} token The token.
|
80 | * @param {express.Request} req The request context.
|
81 | * @param {express.Response} res The response context.
|
82 | */
|
83 | onAccessToken: (token: MicrosoftOAuthAccessToken, req: express.Request, res: express.Response) => void | PromiseLike<void>;
|
84 | /**
|
85 | * A custom error response function.
|
86 | *
|
87 | * @param {string} error The error (code).
|
88 | * @param {string} description The (error) description.
|
89 | * @param {express.Request} req The request context.
|
90 | * @param {express.Response} res The response context.
|
91 | */
|
92 | onError?: (error: string, description: string, req: express.Request, res: express.Response) => any;
|
93 | /**
|
94 | * A custom server error response function.
|
95 | *
|
96 | * @param {any} err The error.
|
97 | * @param {express.Request} req The request context.
|
98 | * @param {express.Response} res The response context.
|
99 | */
|
100 | onServerError?: (err: any, req: express.Request, res: express.Response) => any;
|
101 | /**
|
102 | * A custom success response function.
|
103 | *
|
104 | * @param {express.Request} req The request context.
|
105 | * @param {express.Response} res The response context.
|
106 | */
|
107 | onSuccess?: (req: express.Request, res: express.Response) => any;
|
108 | /**
|
109 | * The custom redirect (base) path. Default: '/oauth/microsoft'
|
110 | */
|
111 | redirectPath?: string;
|
112 | }
|
113 | /**
|
114 | * Returns the information from 'https://graph.microsoft.com/v1.0/me'.
|
115 | *
|
116 | * @param {string | MicrosoftOAuthAccessToken} token The token.
|
117 | *
|
118 | * @return {Promise<false|MicrosoftMe>} The promise with the data or (false) if failed.
|
119 | */
|
120 | export declare function getMicrosoftMe(token: string | MicrosoftOAuthAccessToken): Promise<false | MicrosoftMe>;
|
121 | /**
|
122 | * Returns the login URL for Microsoft OAuth.
|
123 | *
|
124 | * @return {string} The login URL.
|
125 | */
|
126 | export declare function getMicrosoftOAuthLoginUrl(): string;
|
127 | /**
|
128 | * Registers an Express instance for Microsoft OAuth.
|
129 | *
|
130 | * @param {express.Express | express.Router} hostOrRouter The host or router.
|
131 | * @param {RegisterForMicrosoftOAuthOptions} opts The options.
|
132 | */
|
133 | export declare function registerForMicrosoftOAuth(hostOrRouter: express.Express | express.Router, opts: RegisterForMicrosoftOAuthOptions): void;
|