Skip to content

Commit

Permalink
feat: Adding Azure AD auth provider (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
woolfyx committed Dec 21, 2023
1 parent e97580f commit d1c9940
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ GITHUB_SECRET=
GOOGLE_ID=
GOOGLE_SECRET=

AZURE_AD_CLIENT_ID=
AZURE_AD_CLIENT_SECRET=
AZURE_AD_TENANT_ID=

KEYCLOAK_NAME=
KEYCLOAK_ID=
KEYCLOAK_SECRET=
Expand Down
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ model Account {
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
expires_in Int?
ext_expires_in Int?
token_type String?
scope String?
id_token String? @db.Text
Expand Down
10 changes: 10 additions & 0 deletions src/pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import NextAuth from 'next-auth'
import GithubProvider from 'next-auth/providers/github'
import GoogleProvider from 'next-auth/providers/google'
import AzureADProvider from 'next-auth/providers/azure-ad'
import EmailProvider from 'next-auth/providers/email'
import KeycloakProvider from 'next-auth/providers/keycloak'
import AuthentikProvider from 'next-auth/providers/authentik'
Expand All @@ -26,6 +27,15 @@ if (process.env.GOOGLE_ID) {
})
)
}
if (process.env.AZURE_AD_CLIENT_ID) {
providers.push(
AzureADProvider({
clientId: process.env.AZURE_AD_CLIENT_ID,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
tenantId: process.env.AZURE_AD_TENANT_ID,
})
)
}
if (process.env.KEYCLOAK_ID) {
providers.push(
KeycloakProvider({
Expand Down
19 changes: 18 additions & 1 deletion src/pages/auth/signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ const ProviderIcons = ({ provider }) => {
></path>
</svg>
)
} else if (provider === 'azure-ad') {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="21"
height="21"
viewBox="0 0 21 21"
>
<path fill="currentColor" d="m0,0h10v10H0V0Z"></path>
<path fill="currentColor" d="m11,0h10v10h-10V0Z"></path>
<path fill="currentColor" d="m0,11h10v10H0v-10Z"></path>
<path fill="currentColor" d="m11,11h10v10h-10v-10Z"></path>
</svg>
)
} else if (provider === 'keycloak') {
return (
<svg
Expand Down Expand Up @@ -94,7 +108,7 @@ const Signin = ({ providers, csrfToken, autoLoginFirstProvider }) => {
const [email, setEmail] = useState('')
const { query } = useRouter()
const containsOauthProviders = Object.keys(providers).some((p) =>
['google', 'github', 'keycloak', 'authentik'].includes(p)
['google', 'github', 'keycloak', 'authentik', 'azure-ad'].includes(p)
)

if (autoLoginFirstProvider && !query.error) {
Expand Down Expand Up @@ -140,6 +154,9 @@ const Signin = ({ providers, csrfToken, autoLoginFirstProvider }) => {
className={`flex h-10 w-full items-center space-x-2 rounded ${
p.id === 'google' &&
'bg-blue-700 hover:bg-blue-800 focus:ring-blue-700'
} ${
p.id === 'azure-ad' &&
'bg-blue-700 hover:bg-blue-800 focus:ring-blue-700'
} ${
p.id === 'github' &&
'bg-gray-600 hover:bg-gray-800 '
Expand Down

1 comment on commit d1c9940

@vercel
Copy link

@vercel vercel bot commented on d1c9940 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.