Skip to content

Commit

Permalink
initial cognito support
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed Feb 20, 2024
1 parent efd8dda commit a0f8a27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lists-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ bie.url=https://bie-ws.ala.org.au/ws/species/%s
bie.images.url=https://bie.ala.org.au/ws/imageSearch/%s?rows=%s&start=%s
image.url=https://images.ala.org.au/image/%s/large

security.jwt.userIdClaim=username
security.jwt.roleClaims=cognito:groups
security.jwt.requireUserInfo=true
security.jwt.userProfileFromAccessToken=true
security.jwt.rolesFromAccessToken=true
security.jwt.enabled=true
security.jwt.discovery-uri=https://auth-test.ala.org.au/cas/oidc/.well-known
security.jwt.clientId=oidc-events-test
Expand Down
8 changes: 4 additions & 4 deletions lists-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export default function App() {
if (auth.isAuthenticated && auth.user && !currentUser) {
// set the current user
const user = auth.user;
const roles = (user?.profile?.role || []) as string[];
const userId = user?.profile?.userid as string || '';
const roles = (user?.profile?.role || user?.profile["cognito:groups"] || []) as string[];

This comment has been minimized.

Copy link
@djtfmartin

djtfmartin Feb 20, 2024

Member

suggest moving "cognito:groups" out to a property in .env

This comment has been minimized.

Copy link
@adam-collins

adam-collins Feb 26, 2024

Contributor

moved

const userId = (user?.profile?.userid || user?.profile["cognito:username"]) as string || '';
setCurrentUser({
user: auth.user,
userId: userId,
isAdmin: roles.includes('ROLE_ADMIN'),
isAdmin: roles.includes('ROLE_ADMIN') || roles.includes('admin'),
roles: roles
});
}
Expand Down Expand Up @@ -147,7 +147,7 @@ export default function App() {
},
})}>
<Text>
Profile - {currentUser?.user?.profile?.name} {currentUser?.isAdmin ? '(ADMIN)' : ''}
Profile - {currentUser?.user?.profile?.name || (currentUser?.user?.profile?.given_name + ' ' + currentUser?.user?.profile?.family_name)} {currentUser?.isAdmin ? '(ADMIN)' : ''}
</Text>
</Button>
<Button radius="xs" onClick={logout} variant="outline" size="md" compact sx={() => ({
Expand Down

0 comments on commit a0f8a27

Please sign in to comment.