-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab90b2e
commit bf2fc68
Showing
18 changed files
with
281 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
NEXT_PUBLIC_BASE_PATH=/hugin | ||
CATALOGUE_API_PATH=http://localhost:8087/bikube | ||
CATALOGUE_API_PATH=http://localhost:8087/bikube | ||
KEYCLOAK_CLIENT_ID=your-client-id | ||
KEYCLOAK_CLIENT_SECRET=secret | ||
KEYCLOAK_ISSUER=https://your-keycloak-domain.com/realms/your-realm | ||
NEXTAUTH_URL=http://localhost:3000/hugin/api/auth | ||
NEXTAUTH_SECRET=secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention,@typescript-eslint/no-unsafe-assignment */ | ||
import NextAuth, {AuthOptions, TokenSet} from 'next-auth'; | ||
import KeycloakProvider from 'next-auth/providers/keycloak'; | ||
import {JWT} from 'next-auth/jwt'; | ||
|
||
export const authOptions: AuthOptions = { | ||
// debug: true, | ||
providers: [ | ||
KeycloakProvider({ | ||
clientId: process.env.KEYCLOAK_CLIENT_ID ?? '', | ||
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET ?? '', | ||
issuer: process.env.KEYCLOAK_ISSUER | ||
}) | ||
], | ||
session: { | ||
maxAge: 5 * 60 | ||
}, | ||
callbacks: { | ||
async jwt({ token, account }) { | ||
if (account) { | ||
token.idToken = account.id_token!; | ||
token.accessToken = account.access_token!; | ||
token.refreshToken = account.refresh_token!; | ||
token.expiresAt = account.expires_at!; | ||
return token; | ||
} | ||
if (Date.now() < token.expiresAt * 1000 - 10 * 1000) { | ||
return token; | ||
} | ||
try { | ||
const response = await requestRefreshOfAccessToken(token); | ||
const tokens: TokenSet = await response.json(); | ||
|
||
if (!response.ok) throw tokens; | ||
|
||
return { | ||
...token, | ||
accessToken: tokens.access_token!, | ||
expiresAt: Math.floor(Date.now() / 1000 + (tokens.expires_in as number)), | ||
refreshToken: tokens.refresh_token ?? token.refreshToken, | ||
}; | ||
} catch (error) { | ||
console.error('Error refreshing access token', error); | ||
return {...token, error: 'RefreshAccessTokenError' as const}; | ||
} | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async session({ session, token }) { | ||
if (token.accessToken) { | ||
session.idToken = token.idToken; | ||
session.accessToken = token.accessToken; | ||
} | ||
session.error = token.error; | ||
return session; | ||
} | ||
} | ||
}; | ||
|
||
async function requestRefreshOfAccessToken(token: JWT) { | ||
return await fetch(`${process.env.KEYCLOAK_ISSUER}/protocol/openid-connect/token`, { | ||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | ||
body: new URLSearchParams({ | ||
client_id: process.env.KEYCLOAK_CLIENT_ID, | ||
client_secret: process.env.KEYCLOAK_CLIENT_SECRET, | ||
grant_type: 'refresh_token', | ||
refresh_token: token.refreshToken, | ||
}), | ||
method: 'POST' | ||
}); | ||
} | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import NextAuth from 'next-auth'; | ||
import {authOptions} from '@/app/lib/auth'; | ||
|
||
const handler = NextAuth(authOptions); | ||
export { handler as GET, handler as POST }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention,@typescript-eslint/no-unsafe-assignment */ | ||
import {AuthOptions, TokenSet} from 'next-auth'; | ||
import KeycloakProvider from 'next-auth/providers/keycloak'; | ||
import {JWT} from 'next-auth/jwt'; | ||
|
||
export const authOptions: AuthOptions = { | ||
providers: [ | ||
KeycloakProvider({ | ||
clientId: process.env.KEYCLOAK_CLIENT_ID ?? '', | ||
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET ?? '', | ||
issuer: process.env.KEYCLOAK_ISSUER | ||
}) | ||
], | ||
session: { | ||
maxAge: 5 * 60 | ||
}, | ||
callbacks: { | ||
async jwt({ token, account }) { | ||
if (account) { | ||
token.idToken = account.id_token!; | ||
token.accessToken = account.access_token!; | ||
token.refreshToken = account.refresh_token!; | ||
token.expiresAt = account.expires_at!; | ||
return token; | ||
} | ||
if (Date.now() < token.expiresAt * 1000 - 10 * 1000) { | ||
return token; | ||
} | ||
try { | ||
const response = await requestRefreshOfAccessToken(token); | ||
const tokens: TokenSet = await response.json(); | ||
|
||
if (!response.ok) throw tokens; | ||
|
||
return { | ||
...token, | ||
accessToken: tokens.access_token!, | ||
expiresAt: Math.floor(Date.now() / 1000 + (tokens.expires_in as number)), | ||
refreshToken: tokens.refresh_token ?? token.refreshToken, | ||
}; | ||
} catch (error) { | ||
console.error('Error refreshing access token', error); | ||
return {...token, error: 'RefreshAccessTokenError' as const}; | ||
} | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async session({ session, token }) { | ||
if (token.accessToken) { | ||
session.idToken = token.idToken; | ||
session.accessToken = token.accessToken; | ||
} | ||
session.error = token.error; | ||
return session; | ||
} | ||
} | ||
}; | ||
|
||
async function requestRefreshOfAccessToken(token: JWT) { | ||
return await fetch(`${process.env.KEYCLOAK_ISSUER}/protocol/openid-connect/token`, { | ||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | ||
body: new URLSearchParams({ | ||
client_id: process.env.KEYCLOAK_CLIENT_ID, | ||
client_secret: process.env.KEYCLOAK_CLIENT_SECRET, | ||
grant_type: 'refresh_token', | ||
refresh_token: token.refreshToken, | ||
}), | ||
method: 'POST' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import SearchBar from '@/components/SearchBar'; | ||
import Image from 'next/image'; | ||
import {Providers} from '@/app/providers'; | ||
|
||
export default function Home() { | ||
return ( | ||
<div className="w-96 flex flex-col items-center justify-start"> | ||
<Image className="m-5" src="/hugin/hugin.svg" alt="Hugin logo" width={128} height={128}/> | ||
<SearchBar /> | ||
</div> | ||
<Providers> | ||
<div className="w-96 flex flex-col items-center justify-start"> | ||
<Image className="m-5" src="/hugin/hugin.svg" alt="Hugin logo" width={128} height={128}/> | ||
<SearchBar/> | ||
</div> | ||
</Providers> | ||
); | ||
} |
Oops, something went wrong.