Skip to content

Commit

Permalink
feat: support microsoft-entra-id sso login
Browse files Browse the repository at this point in the history
  • Loading branch information
EINDEX authored Sep 27, 2024
1 parent 6eb2b22 commit 31c322a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libs/next-auth/sso-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Auth0 from './auth0';
import Authelia from './authelia';
import Authentik from './authentik';
import AzureAD from './azure-ad';
import MicrosoftEntraID from 'microsoft-entra-id';
import Casdoor from './casdoor';
import CloudflareZeroTrust from './cloudflare-zero-trust';
import GenericOIDC from './generic-oidc';
Expand All @@ -20,4 +21,5 @@ export const ssoProviders = [
Logto,
CloudflareZeroTrust,
Casdoor,
MicrosoftEntraID,
];
32 changes: 32 additions & 0 deletions src/libs/next-auth/sso-providers/microsoft-entra-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import MicrosoftEntraID from "next-auth/providers/microsoft-entra-id"

import { authEnv } from '@/config/auth';

import { CommonProviderConfig } from './sso.config';

const provider = {
id: 'microsoft-entra-id',
provider: MicrosoftEntraID({
...CommonProviderConfig,
// Specify auth scope, at least include 'openid email'
// all scopes in Azure AD ref: https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc#openid-connect-scopes
authorization: { params: { scope: 'openid email profile' } },
// TODO(NextAuth ENVs Migration): Remove once nextauth envs migration time end
clientId: authEnv.MICROSOFT_ENTRA_ID_ID ?? process.env.AUTH_MICROSOFT_ENTRA_ID_ID,
clientSecret: authEnv.MICROSOFT_ENTRA_ID_SECRET ?? process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET,
tenantId: authEnv.MICROSOFT_ENTRA_ID_TENANT_ID ?? process.env.AUTH_MICROSOFT_ENTRA_ID_TENANT_ID,
// Remove end
// TODO(NextAuth): map unique user id to `providerAccountId` field
// profile(profile) {
// return {
// email: profile.email,
// image: profile.picture,
// name: profile.name,
// providerAccountId: profile.user_id,
// id: profile.user_id,
// };
// },
}),
};

export default provider;

0 comments on commit 31c322a

Please sign in to comment.