alp-node-auth 7.2.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/dist/definitions/MongoUsersManager.d.ts +4 -2
- package/dist/definitions/MongoUsersManager.d.ts.map +1 -1
- package/dist/definitions/authApolloContext.d.ts +2 -2
- package/dist/definitions/authApolloContext.d.ts.map +1 -1
- package/dist/definitions/authSocketIO.d.ts +2 -2
- package/dist/definitions/authSocketIO.d.ts.map +1 -1
- package/dist/definitions/createAuthController.d.ts +2 -2
- package/dist/definitions/createAuthController.d.ts.map +1 -1
- package/dist/definitions/index.d.ts +10 -9
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/services/authentification/AuthenticationService.d.ts +6 -12
- package/dist/definitions/services/authentification/AuthenticationService.d.ts.map +1 -1
- package/dist/definitions/services/authentification/types.d.ts +2 -2
- package/dist/definitions/services/authentification/types.d.ts.map +1 -1
- package/dist/definitions/services/user/UserAccountSlackService.d.ts.map +1 -1
- package/dist/definitions/services/user/UserAccountsService.d.ts +2 -2
- package/dist/definitions/services/user/UserAccountsService.d.ts.map +1 -1
- package/dist/definitions/services/user/types.d.ts +2 -2
- package/dist/definitions/services/user/types.d.ts.map +1 -1
- package/dist/definitions/types.d.ts +42 -0
- package/dist/definitions/types.d.ts.map +1 -0
- package/dist/definitions/utils/cookies.d.ts +3 -2
- package/dist/definitions/utils/cookies.d.ts.map +1 -1
- package/dist/definitions/utils/createFindLoggedInUser.d.ts +6 -0
- package/dist/definitions/utils/createFindLoggedInUser.d.ts.map +1 -0
- package/dist/{index-node16.mjs → index-node18.mjs} +125 -80
- package/dist/index-node18.mjs.map +1 -0
- package/package.json +67 -30
- package/src/MongoUsersManager.ts +8 -2
- package/src/authApolloContext.ts +10 -10
- package/src/authSocketIO.ts +9 -8
- package/src/createAuthController.ts +10 -9
- package/src/index.ts +74 -46
- package/src/services/authentification/AuthenticationService.ts +30 -33
- package/src/services/authentification/types.ts +2 -2
- package/src/services/user/UserAccountGoogleService.ts +1 -1
- package/src/services/user/UserAccountSlackService.ts +2 -8
- package/src/services/user/UserAccountsService.ts +10 -5
- package/src/services/user/types.ts +2 -2
- package/{types.d.ts → src/types.ts} +2 -3
- package/src/utils/cookies.ts +8 -3
- package/src/utils/{createFindConnectedAndUser.ts → createFindLoggedInUser.ts} +19 -20
- package/src/utils/generators.ts +2 -2
- package/strategies/dropbox.js +22 -12
- package/strategies/facebook.js +22 -12
- package/strategies/foursquare.js +22 -12
- package/strategies/github.js +22 -12
- package/strategies/google.js +23 -12
- package/strategies/slack.js +22 -12
- package/strategies/strategies.d.ts +9 -4
- package/dist/definitions/utils/createFindConnectedAndUser.d.ts +0 -6
- package/dist/definitions/utils/createFindConnectedAndUser.d.ts.map +0 -1
- package/dist/index-node16.mjs.map +0 -1
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
4
|
/* eslint-disable camelcase, max-lines */
|
|
5
|
-
import { EventEmitter } from 'events';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
6
|
import 'alp-router';
|
|
7
7
|
import type { Context, NodeConfig } from 'alp-types';
|
|
8
8
|
import { Logger } from 'nightingale-logger';
|
|
9
|
-
import type {
|
|
10
|
-
import type { AccountId, User, Account, UserSanitized } from '
|
|
9
|
+
import type { Strategy as Oauth2Strategy } from '../../../strategies/strategies.d';
|
|
10
|
+
import type { AccountId, User, Account, UserSanitized } from '../../types';
|
|
11
11
|
import { randomHex } from '../../utils/generators';
|
|
12
12
|
import type UserAccountsService from '../user/UserAccountsService';
|
|
13
13
|
import type { AllowedStrategyKeys, Tokens } from './types';
|
|
@@ -30,14 +30,6 @@ export interface GetTokensOptions {
|
|
|
30
30
|
redirectUri: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export interface Strategy {
|
|
34
|
-
type: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface Oauth2Strategy<Params extends string> extends Strategy {
|
|
38
|
-
oauth2: OAuthClient<Params>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
33
|
export type Strategies<StrategyKeys extends AllowedStrategyKeys> = Record<
|
|
42
34
|
StrategyKeys,
|
|
43
35
|
Oauth2Strategy<any>
|
|
@@ -46,21 +38,22 @@ export type Strategies<StrategyKeys extends AllowedStrategyKeys> = Record<
|
|
|
46
38
|
export interface AccessResponseHooks<StrategyKeys, U extends User = User> {
|
|
47
39
|
afterLoginSuccess?: <StrategyKey extends StrategyKeys>(
|
|
48
40
|
strategy: StrategyKey,
|
|
49
|
-
|
|
50
|
-
) => void |
|
|
41
|
+
loggedInUser: U,
|
|
42
|
+
) => Promise<void> | void;
|
|
51
43
|
|
|
52
44
|
afterScopeUpdate?: <StrategyKey extends StrategyKeys>(
|
|
53
45
|
strategy: StrategyKey,
|
|
54
46
|
scopeKey: string,
|
|
55
47
|
account: Account,
|
|
56
48
|
user: U,
|
|
57
|
-
) => void |
|
|
49
|
+
) => Promise<void> | void;
|
|
58
50
|
}
|
|
59
51
|
|
|
60
52
|
export class AuthenticationService<
|
|
61
53
|
StrategyKeys extends AllowedStrategyKeys,
|
|
62
54
|
U extends User = User,
|
|
63
55
|
USanitized extends UserSanitized = UserSanitized,
|
|
56
|
+
// eslint-disable-next-line unicorn/prefer-event-target
|
|
64
57
|
> extends EventEmitter {
|
|
65
58
|
config: NodeConfig;
|
|
66
59
|
|
|
@@ -105,17 +98,20 @@ export class AuthenticationService<
|
|
|
105
98
|
},
|
|
106
99
|
);
|
|
107
100
|
if (!result) return result;
|
|
101
|
+
const tokens = result.token;
|
|
102
|
+
|
|
108
103
|
return {
|
|
109
|
-
accessToken:
|
|
110
|
-
refreshToken:
|
|
111
|
-
tokenType:
|
|
112
|
-
expiresIn:
|
|
104
|
+
accessToken: tokens.access_token as string,
|
|
105
|
+
refreshToken: tokens.refresh_token as string,
|
|
106
|
+
tokenType: tokens.token_type as string,
|
|
107
|
+
expiresIn: tokens.expires_in as number,
|
|
113
108
|
expireDate: (() => {
|
|
109
|
+
if (tokens.expires_in == null) return null;
|
|
114
110
|
const d = new Date();
|
|
115
|
-
d.setTime(d.getTime() +
|
|
111
|
+
d.setTime(d.getTime() + (tokens.expires_in as number) * 1000);
|
|
116
112
|
return d;
|
|
117
113
|
})(),
|
|
118
|
-
idToken:
|
|
114
|
+
idToken: tokens.id_token as string,
|
|
119
115
|
};
|
|
120
116
|
// return strategyInstance.accessToken.create(result);
|
|
121
117
|
}
|
|
@@ -136,21 +132,22 @@ export class AuthenticationService<
|
|
|
136
132
|
const strategyInstance = this.strategies[strategy];
|
|
137
133
|
switch (strategyInstance.type) {
|
|
138
134
|
case 'oauth2': {
|
|
139
|
-
const token = strategyInstance.oauth2.
|
|
135
|
+
const token = strategyInstance.oauth2.clientCredentials.createToken({
|
|
140
136
|
refresh_token: tokensParam.refreshToken,
|
|
141
137
|
});
|
|
142
138
|
const result = await token.refresh();
|
|
143
139
|
const tokens = result.token;
|
|
144
140
|
return {
|
|
145
|
-
accessToken: tokens.access_token,
|
|
146
|
-
tokenType: tokens.token_type,
|
|
147
|
-
expiresIn: tokens.expires_in,
|
|
141
|
+
accessToken: tokens.access_token as string,
|
|
142
|
+
tokenType: tokens.token_type as string,
|
|
143
|
+
expiresIn: tokens.expires_in as number,
|
|
148
144
|
expireDate: (() => {
|
|
145
|
+
if (tokens.expires_in == null) return null;
|
|
149
146
|
const d = new Date();
|
|
150
|
-
d.setTime(d.getTime() + tokens.expires_in * 1000);
|
|
147
|
+
d.setTime(d.getTime() + (tokens.expires_in as number) * 1000);
|
|
151
148
|
return d;
|
|
152
149
|
})(),
|
|
153
|
-
idToken: tokens.id_token,
|
|
150
|
+
idToken: tokens.id_token as string,
|
|
154
151
|
};
|
|
155
152
|
}
|
|
156
153
|
|
|
@@ -223,9 +220,9 @@ export class AuthenticationService<
|
|
|
223
220
|
}
|
|
224
221
|
|
|
225
222
|
async accessResponse<StrategyKey extends StrategyKeys>(
|
|
226
|
-
ctx:
|
|
223
|
+
ctx: Context,
|
|
227
224
|
strategy: StrategyKey,
|
|
228
|
-
|
|
225
|
+
isLoggedIn: boolean,
|
|
229
226
|
hooks: AccessResponseHooks<StrategyKeys, U>,
|
|
230
227
|
): Promise<U> {
|
|
231
228
|
if (ctx.query.error) {
|
|
@@ -245,12 +242,12 @@ export class AuthenticationService<
|
|
|
245
242
|
}
|
|
246
243
|
|
|
247
244
|
cookie = JSON.parse(cookie);
|
|
248
|
-
if (!cookie
|
|
245
|
+
if (!cookie?.scope) {
|
|
249
246
|
throw new Error('Unexpected cookie value');
|
|
250
247
|
}
|
|
251
248
|
|
|
252
249
|
if (!cookie.isLoginAccess) {
|
|
253
|
-
if (!
|
|
250
|
+
if (!isLoggedIn) {
|
|
254
251
|
throw new Error('You are not connected');
|
|
255
252
|
}
|
|
256
253
|
}
|
|
@@ -275,9 +272,9 @@ export class AuthenticationService<
|
|
|
275
272
|
return user;
|
|
276
273
|
}
|
|
277
274
|
|
|
278
|
-
const
|
|
275
|
+
const loggedInUser = ctx.state.loggedInUser as U;
|
|
279
276
|
const { account, user } = await this.userAccountsService.update(
|
|
280
|
-
|
|
277
|
+
loggedInUser,
|
|
281
278
|
strategy,
|
|
282
279
|
tokens,
|
|
283
280
|
cookie.scope,
|
|
@@ -288,7 +285,7 @@ export class AuthenticationService<
|
|
|
288
285
|
await hooks.afterScopeUpdate(strategy, cookie.scopeKey, account, user);
|
|
289
286
|
}
|
|
290
287
|
|
|
291
|
-
return
|
|
288
|
+
return loggedInUser;
|
|
292
289
|
}
|
|
293
290
|
|
|
294
291
|
refreshAccountTokens(user: U, account: Account): Promise<boolean> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/class-methods-use-this */
|
|
1
2
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
3
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
|
-
import { fetch } from 'alp-node';
|
|
4
4
|
import type { Tokens } from '../authentification/types';
|
|
5
5
|
import type { AccountService, FullName } from './types';
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/class-methods-use-this */
|
|
1
2
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
-
import { fetch } from 'alp-node';
|
|
3
3
|
import type { Tokens } from '../authentification/types';
|
|
4
4
|
import type { AccountService, FullName } from './types';
|
|
5
5
|
|
|
@@ -26,13 +26,7 @@ export default class UserAccountSlackService<ScopeKeys extends 'login'>
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
getId(profile: any): string | null {
|
|
29
|
-
if (
|
|
30
|
-
!profile ||
|
|
31
|
-
!profile.team ||
|
|
32
|
-
!profile.team.id ||
|
|
33
|
-
!profile.user ||
|
|
34
|
-
!profile.user.id
|
|
35
|
-
) {
|
|
29
|
+
if (!profile?.team?.id || !profile.user?.id) {
|
|
36
30
|
return null;
|
|
37
31
|
}
|
|
38
32
|
return `team:${profile.team.id as string};user:${
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
3
|
import { Logger } from 'nightingale-logger';
|
|
4
|
-
import type { AccountId, User, Account, UserSanitized } from '../../../types.d';
|
|
5
4
|
import type MongoUsersManager from '../../MongoUsersManager';
|
|
5
|
+
import type { AccountId, User, Account, UserSanitized } from '../../types';
|
|
6
6
|
import type { AllowedStrategyKeys } from '../authentification/types';
|
|
7
7
|
import type { AccountService, TokensObject } from './types';
|
|
8
8
|
|
|
@@ -17,6 +17,7 @@ export default class UserAccountsService<
|
|
|
17
17
|
StrategyKeys extends AllowedStrategyKeys,
|
|
18
18
|
U extends User = User,
|
|
19
19
|
USanitized extends UserSanitized = UserSanitized,
|
|
20
|
+
// eslint-disable-next-line unicorn/prefer-event-target
|
|
20
21
|
> extends EventEmitter {
|
|
21
22
|
private readonly strategyToService: Record<StrategyKeys, AccountService<any>>;
|
|
22
23
|
|
|
@@ -82,7 +83,7 @@ export default class UserAccountsService<
|
|
|
82
83
|
if (tokens.refreshToken) {
|
|
83
84
|
account.refreshToken = tokens.refreshToken;
|
|
84
85
|
}
|
|
85
|
-
if (tokens.expireDate) {
|
|
86
|
+
if (tokens.expireDate !== undefined) {
|
|
86
87
|
account.tokenExpireDate = tokens.expireDate;
|
|
87
88
|
}
|
|
88
89
|
account.scope = service.getScope(account.scope, scope);
|
|
@@ -117,7 +118,11 @@ export default class UserAccountsService<
|
|
|
117
118
|
emails,
|
|
118
119
|
});
|
|
119
120
|
|
|
120
|
-
logger.info(!user ? 'create user' : 'existing user', {
|
|
121
|
+
logger.info(!user ? 'create user' : 'existing user', {
|
|
122
|
+
userId: user?._id,
|
|
123
|
+
accountId,
|
|
124
|
+
/*emails , user*/
|
|
125
|
+
});
|
|
121
126
|
|
|
122
127
|
if (!user) {
|
|
123
128
|
user = {};
|
|
@@ -149,7 +154,7 @@ export default class UserAccountsService<
|
|
|
149
154
|
if (tokens.refreshToken) {
|
|
150
155
|
account.refreshToken = tokens.refreshToken;
|
|
151
156
|
}
|
|
152
|
-
if (tokens.expireDate) {
|
|
157
|
+
if (tokens.expireDate !== undefined) {
|
|
153
158
|
account.tokenExpireDate = tokens.expireDate;
|
|
154
159
|
}
|
|
155
160
|
account.scope = service.getScope(account.scope, scope);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { MongoBaseModel } from 'liwi-mongo';
|
|
1
|
+
import type { MongoBaseModel } from 'liwi-mongo';
|
|
2
2
|
|
|
3
|
-
/* eslint-disable no-restricted-globals */
|
|
4
3
|
export interface UserName {
|
|
5
4
|
familyName: string;
|
|
6
5
|
givenName: string;
|
|
@@ -18,7 +17,7 @@ export interface Account {
|
|
|
18
17
|
scope: string[];
|
|
19
18
|
subservices?: string[];
|
|
20
19
|
status: string;
|
|
21
|
-
tokenExpireDate: Date;
|
|
20
|
+
tokenExpireDate: Date | null;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export interface User extends MongoBaseModel {
|
package/src/utils/cookies.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import type { IncomingMessage } from 'http';
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { Option } from 'cookies';
|
|
3
3
|
import Cookies from 'cookies';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const COOKIE_NAME_TOKEN = 'loggedInUserToken';
|
|
6
|
+
export const COOKIE_NAME_STATE = 'loggedInUserState';
|
|
6
7
|
|
|
7
8
|
export const getTokenFromRequest = (
|
|
8
9
|
req: IncomingMessage,
|
|
9
10
|
options?: Pick<Option, Exclude<keyof Option, 'secure'>>,
|
|
10
11
|
): string | undefined => {
|
|
12
|
+
if (req.headers.authorization?.startsWith('Bearer ')) {
|
|
13
|
+
return req.headers.authorization.slice('Bearer '.length);
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
12
17
|
const cookies = new Cookies(req, null as unknown as any, {
|
|
13
18
|
...options,
|
|
14
19
|
secure: true,
|
|
15
20
|
});
|
|
16
21
|
|
|
17
|
-
return cookies.get(
|
|
22
|
+
return cookies.get(COOKIE_NAME_TOKEN);
|
|
18
23
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { promisify } from 'util';
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
2
|
import type {
|
|
3
3
|
GetPublicKeyOrSecret,
|
|
4
4
|
Secret,
|
|
@@ -7,12 +7,12 @@ import type {
|
|
|
7
7
|
} from 'jsonwebtoken';
|
|
8
8
|
import jsonwebtoken from 'jsonwebtoken';
|
|
9
9
|
import type { Logger } from 'nightingale-logger';
|
|
10
|
-
import type { User, UserSanitized } from '../../types.d';
|
|
11
10
|
import type MongoUsersManager from '../MongoUsersManager';
|
|
11
|
+
import type { User, UserSanitized } from '../types';
|
|
12
12
|
|
|
13
13
|
type Verify = (
|
|
14
14
|
token: string,
|
|
15
|
-
secretOrPublicKey:
|
|
15
|
+
secretOrPublicKey: GetPublicKeyOrSecret | Secret,
|
|
16
16
|
options?: VerifyOptions,
|
|
17
17
|
callback?: VerifyCallback,
|
|
18
18
|
) => void;
|
|
@@ -31,43 +31,42 @@ const createDecodeJWT =
|
|
|
31
31
|
algorithms: ['HS512'],
|
|
32
32
|
audience: jwtAudience,
|
|
33
33
|
});
|
|
34
|
-
return (result as any)?.
|
|
34
|
+
return (result as any)?.loggedInUserId as string | undefined;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export type
|
|
37
|
+
export type FindLoggedInUser<U extends User> = (
|
|
38
38
|
jwtAudience?: string,
|
|
39
39
|
token?: string,
|
|
40
|
-
) => Promise<[
|
|
40
|
+
) => Promise<[U['_id'] | null | undefined, U | null | undefined]>;
|
|
41
41
|
|
|
42
|
-
export const
|
|
42
|
+
export const createFindLoggedInUser = <
|
|
43
43
|
U extends User,
|
|
44
44
|
USanitized extends UserSanitized,
|
|
45
45
|
>(
|
|
46
46
|
secretKey: string,
|
|
47
47
|
usersManager: MongoUsersManager<U, USanitized>,
|
|
48
48
|
logger: Logger,
|
|
49
|
-
):
|
|
49
|
+
): FindLoggedInUser<U> => {
|
|
50
50
|
const decodeJwt = createDecodeJWT(secretKey);
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
jwtAudience,
|
|
54
|
-
token,
|
|
55
|
-
) => {
|
|
52
|
+
const findLoggedInUser: FindLoggedInUser<U> = async (jwtAudience, token) => {
|
|
56
53
|
if (!token || !jwtAudience) return [null, null];
|
|
57
54
|
|
|
58
|
-
let
|
|
55
|
+
let loggedInUserId;
|
|
59
56
|
try {
|
|
60
|
-
|
|
61
|
-
} catch (
|
|
62
|
-
logger.debug('failed to verify authentification', { err });
|
|
57
|
+
loggedInUserId = await decodeJwt(token, jwtAudience);
|
|
58
|
+
} catch (error: unknown) {
|
|
59
|
+
logger.debug('failed to verify authentification', { err: error });
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
if (
|
|
62
|
+
if (loggedInUserId == null) return [null, null];
|
|
66
63
|
|
|
67
|
-
const
|
|
64
|
+
const loggedInUser = await usersManager.findById(loggedInUserId);
|
|
68
65
|
|
|
69
|
-
return [
|
|
66
|
+
if (!loggedInUser) return [null, null];
|
|
67
|
+
|
|
68
|
+
return [loggedInUserId, loggedInUser];
|
|
70
69
|
};
|
|
71
70
|
|
|
72
|
-
return
|
|
71
|
+
return findLoggedInUser;
|
|
73
72
|
};
|
package/src/utils/generators.ts
CHANGED
package/strategies/dropbox.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function dropboxStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('dropbox').get('clientId'),
|
|
7
|
+
secret: config.get('dropbox').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://www.dropbox.com',
|
|
11
|
+
tokenPath: '/1/oauth2/token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/1/oauth2/authorize',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
4
21
|
return {
|
|
5
22
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://www.dropbox.com',
|
|
13
|
-
tokenPath: '/1/oauth2/token',
|
|
14
|
-
authorizePath: '/1/oauth2/authorize',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
23
|
+
oauth2: {
|
|
24
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
25
|
+
clientCredentials: new ClientCredentials(options),
|
|
26
|
+
},
|
|
17
27
|
};
|
|
18
28
|
}
|
package/strategies/facebook.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function facebookStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('facebook').get('clientId'),
|
|
7
|
+
secret: config.get('facebook').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://www.facebook.com',
|
|
11
|
+
tokenPath: '/oauth/access_token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/dialog/oauth',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
4
21
|
return {
|
|
5
22
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://www.facebook.com',
|
|
13
|
-
tokenPath: '/oauth/access_token',
|
|
14
|
-
authorizePath: '/dialog/oauth',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
23
|
+
oauth2: {
|
|
24
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
25
|
+
clientCredentials: new ClientCredentials(options),
|
|
26
|
+
},
|
|
17
27
|
};
|
|
18
28
|
}
|
package/strategies/foursquare.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function foursquareStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('foursquare').get('clientId'),
|
|
7
|
+
secret: config.get('foursquare').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://foursquare.com',
|
|
11
|
+
tokenPath: '/oauth2/access_token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/oauth2/authenticate',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
4
21
|
return {
|
|
5
22
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://foursquare.com',
|
|
13
|
-
tokenPath: '/oauth2/access_token',
|
|
14
|
-
authorizePath: '/oauth2/authenticate',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
23
|
+
oauth2: {
|
|
24
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
25
|
+
clientCredentials: new ClientCredentials(options),
|
|
26
|
+
},
|
|
17
27
|
};
|
|
18
28
|
}
|
package/strategies/github.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function githubStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('github').get('clientId'),
|
|
7
|
+
secret: config.get('github').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://github.com',
|
|
11
|
+
tokenPath: '/login/oauth/access_token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/login/oauth/authorize',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
4
21
|
return {
|
|
5
22
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://github.com',
|
|
13
|
-
tokenPath: '/login/oauth/access_token',
|
|
14
|
-
authorizePath: '/login/oauth/authorize',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
23
|
+
oauth2: {
|
|
24
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
25
|
+
clientCredentials: new ClientCredentials(options),
|
|
26
|
+
},
|
|
17
27
|
};
|
|
18
28
|
}
|
package/strategies/google.js
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function googleStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('google').get('clientId'),
|
|
7
|
+
secret: config.get('google').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://accounts.google.com',
|
|
11
|
+
tokenPath: '/o/oauth2/token',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/o/oauth2/auth',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
4
22
|
return {
|
|
5
23
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://accounts.google.com',
|
|
13
|
-
tokenPath: '/o/oauth2/token',
|
|
14
|
-
authorizePath: '/o/oauth2/auth',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
24
|
+
oauth2: {
|
|
25
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
26
|
+
clientCredentials: new ClientCredentials(options),
|
|
27
|
+
},
|
|
17
28
|
};
|
|
18
29
|
}
|
package/strategies/slack.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
2
2
|
|
|
3
3
|
export default function slackStrategy(config) {
|
|
4
|
+
const options = {
|
|
5
|
+
client: {
|
|
6
|
+
id: config.get('slack').get('clientId'),
|
|
7
|
+
secret: config.get('slack').get('clientSecret'),
|
|
8
|
+
},
|
|
9
|
+
auth: {
|
|
10
|
+
tokenHost: 'https://slack.com',
|
|
11
|
+
tokenPath: '/api/oauth.access',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const authOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
auth: {
|
|
17
|
+
...options.auth,
|
|
18
|
+
authorizePath: '/oauth/authorize',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
4
21
|
return {
|
|
5
22
|
type: 'oauth2',
|
|
6
|
-
oauth2:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
auth: {
|
|
12
|
-
tokenHost: 'https://slack.com',
|
|
13
|
-
tokenPath: '/api/oauth.access',
|
|
14
|
-
authorizePath: '/oauth/authorize',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
23
|
+
oauth2: {
|
|
24
|
+
authorizationCode: new AuthorizationCode(authOptions),
|
|
25
|
+
clientCredentials: new ClientCredentials(options),
|
|
26
|
+
},
|
|
17
27
|
};
|
|
18
28
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Config, SlackParams } from 'alp-types';
|
|
2
|
-
import {
|
|
2
|
+
import { ClientCredentials, AuthorizationCode } from 'simple-oauth2';
|
|
3
3
|
|
|
4
|
-
export interface Strategy {
|
|
4
|
+
export interface Strategy<Params = SlackParams> {
|
|
5
5
|
type: 'oauth2';
|
|
6
|
-
oauth2:
|
|
6
|
+
oauth2: {
|
|
7
|
+
authorizationCode: AuthorizationCode<Params>;
|
|
8
|
+
clientCredentials: ClientCredentials<Params>;
|
|
9
|
+
};
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
export default function createStrategy
|
|
12
|
+
export default function createStrategy<Params = SlackParams>(
|
|
13
|
+
config: Config,
|
|
14
|
+
): Strategy<Params>;
|