|
1 | 1 | // @ts-expect-error no declaration file for this |
2 | | -import AzureAdOAuth2Strategy from 'passport-azure-ad-oauth2' |
3 | | -import { decode } from 'jsonwebtoken' |
| 2 | + |
| 3 | +import { decode } from "jsonwebtoken"; |
| 4 | +import AzureAdOAuth2Strategy from "passport-azure-ad-oauth2"; |
4 | 5 |
|
5 | 6 | export type Env = { |
6 | | - int: (key: string, defaultValue?: number) => number |
7 | | - array: (key: string, defaultValue?: string[]) => string[] |
8 | | - float: (key: string, defaultValue?: number) => number |
9 | | - bool: (key: string, defaultValue?: boolean) => boolean |
10 | | - json: (key: string, defaultValue?: any) => any |
11 | | - date: (key: string, defaultValue?: Date) => Date |
| 7 | + int: (key: string, defaultValue?: number) => number; |
| 8 | + array: (key: string, defaultValue?: string[]) => string[]; |
| 9 | + float: (key: string, defaultValue?: number) => number; |
| 10 | + bool: (key: string, defaultValue?: boolean) => boolean; |
| 11 | + json: (key: string, defaultValue?: any) => any; |
| 12 | + date: (key: string, defaultValue?: Date) => Date; |
12 | 13 | } & ((key: string, defaultValue?: string) => string) & |
13 | | - ((key: string, defaultValue?: number) => number) |
| 14 | + ((key: string, defaultValue?: number) => number); |
14 | 15 |
|
15 | 16 | export default ({ env }: { env: Env }) => ({ |
16 | | - transfer: { |
17 | | - token: { |
18 | | - salt: env('TRANSFER_TOKEN_SALT'), |
19 | | - }, |
20 | | - }, |
21 | | - auth: { |
22 | | - secret: env('ADMIN_JWT_SECRET', 'c0b47f9208b27587591171747a858bc8'), |
23 | | - providers: [ |
24 | | - { |
25 | | - uid: 'azure_ad_oauth2', |
26 | | - displayName: 'Microsoft', |
27 | | - icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Microsoft_logo.svg/480px-Microsoft_logo.svg.png', |
28 | | - createStrategy: (strapi: { |
29 | | - admin: { services: { passport: { getStrategyCallbackURL: (arg0: string) => any } } } |
30 | | - }) => |
31 | | - new AzureAdOAuth2Strategy( |
32 | | - { |
33 | | - clientID: env('MICROSOFT_CLIENT_ID', ''), |
34 | | - clientSecret: env('MICROSOFT_CLIENT_SECRET', ''), |
35 | | - scope: ['user:profile'], |
36 | | - tenant: env('MICROSOFT_TENANT_ID', ''), |
37 | | - callbackURL: strapi.admin.services.passport.getStrategyCallbackURL('azure_ad_oauth2'), |
38 | | - }, |
39 | | - ( |
40 | | - accessToken: string, |
41 | | - refreshToken: any, |
42 | | - params: { id_token: string }, |
43 | | - profile: any, |
44 | | - done: ( |
45 | | - arg0: any, |
46 | | - arg1: { email: any; username: any; firstname: any; lastname: any }, |
47 | | - ) => void, |
48 | | - ) => { |
49 | | - const waadProfile = decode(params.id_token) |
50 | | - const prof = decode(accessToken, { json: true }) |
51 | | - if (!prof) return |
52 | | - done(null, { |
53 | | - email: prof.upn, |
54 | | - username: prof.upn, |
55 | | - firstname: prof.given_name || prof.name, |
56 | | - lastname: prof.family_name || !prof.given_name ? prof.name : undefined, |
57 | | - }) |
58 | | - }, |
59 | | - ), |
60 | | - }, |
61 | | - ], |
62 | | - }, |
63 | | - url: '/admin', |
64 | | -}) |
| 17 | + transfer: { |
| 18 | + token: { |
| 19 | + salt: env("TRANSFER_TOKEN_SALT"), |
| 20 | + }, |
| 21 | + }, |
| 22 | + auth: { |
| 23 | + secret: env("ADMIN_JWT_SECRET", "c0b47f9208b27587591171747a858bc8"), |
| 24 | + providers: [ |
| 25 | + { |
| 26 | + uid: "azure_ad_oauth2", |
| 27 | + displayName: "Microsoft", |
| 28 | + icon: "https://upload.wikimedia.org/wikipedia/commons/9/96/Microsoft_logo_(2012).svg", |
| 29 | + createStrategy: (strapi: { |
| 30 | + admin: { |
| 31 | + services: { |
| 32 | + passport: { getStrategyCallbackURL: (arg0: string) => any }; |
| 33 | + }; |
| 34 | + }; |
| 35 | + }) => |
| 36 | + new AzureAdOAuth2Strategy( |
| 37 | + { |
| 38 | + clientID: env("MICROSOFT_CLIENT_ID", ""), |
| 39 | + clientSecret: env("MICROSOFT_CLIENT_SECRET", ""), |
| 40 | + scope: ["user:profile"], |
| 41 | + tenant: env("MICROSOFT_TENANT_ID", ""), |
| 42 | + callbackURL: |
| 43 | + strapi.admin.services.passport.getStrategyCallbackURL( |
| 44 | + "azure_ad_oauth2", |
| 45 | + ), |
| 46 | + }, |
| 47 | + ( |
| 48 | + accessToken: string, |
| 49 | + refreshToken: any, |
| 50 | + params: { id_token: string }, |
| 51 | + profile: any, |
| 52 | + done: ( |
| 53 | + arg0: any, |
| 54 | + arg1: { |
| 55 | + email: any; |
| 56 | + username: any; |
| 57 | + firstname: any; |
| 58 | + lastname: any; |
| 59 | + }, |
| 60 | + ) => void, |
| 61 | + ) => { |
| 62 | + const waadProfile = decode(params.id_token); |
| 63 | + const prof = decode(accessToken, { json: true }); |
| 64 | + if (!prof) return; |
| 65 | + done(null, { |
| 66 | + email: prof.upn, |
| 67 | + username: prof.upn, |
| 68 | + firstname: prof.given_name || prof.name, |
| 69 | + lastname: |
| 70 | + prof.family_name || !prof.given_name ? prof.name : undefined, |
| 71 | + }); |
| 72 | + }, |
| 73 | + ), |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + url: "/admin", |
| 78 | +}); |
0 commit comments