-
Notifications
You must be signed in to change notification settings - Fork 1
Appt 1413: Authentication refactor to the front end #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| throw Error('No provider found in request'); | ||
| } | ||
|
|
||
| const authProvider = getProvider(provider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This route is only designed for a direct provider, should error out if it's not
| throw new Error(`Provider ${provider} not found`); | ||
| } | ||
|
|
||
| const tokenResponse = await fetch(authProvider.TOKEN_URL, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this was in the API we would log the fact the User had logged in, do we need to keep this and add it somewhere in here?
| client_id: authProvider.CLIENT_ID, | ||
| code: code, | ||
| redirect_uri: `http://localhost:3000/manage-your-appointments/auth/set-cookie-v2?provider=${authProvider.NAME}`, | ||
| scope: `openid profile email${authProvider.OFFLINE_ACCESS_ENABLED ? ' offline_access' : ''}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When offline access is enabled this is when we should create a session and enable refreshing the token
| OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:4318/v1/metrics | ||
| OTEL_SERVICE_NAME=mya-web-app | ||
| NODE_TLS_REJECT_UNAUTHORIZED=0 | ||
| AUTH_PROVIDERS=[{"NAME": "nhs-mail","HOST_URL": "http://localhost:8020/connect/authorize","IS_DIRECT": true,"OFFLINE_ACCESS_ENABLED": true,"TOKEN_URL": "http://localhost:8020/connect/token","CLIENT_ID": "nhs-appts-local","CODE_CHALLENGE": "ThisIsntRandomButItNeedsToBe43CharactersLong"},{"NAME": "nhs-mail","HOST_URL":"http://localhost:7071/api/authenticate","IS_DIRECT": false}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there's a better way to add these variables :)
| OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4318/v1/traces | ||
| OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://localhost:4318/v1/metrics | ||
| OTEL_SERVICE_NAME=mya-web-app | ||
| NODE_TLS_REJECT_UNAUTHORIZED=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock oidc server throws an SSL error NODE_TLS_REJECT_UNAUTHORIZED added to get round it

Description
As part of a spike to add the ability to refresh a cookie in MYA, we looked at how much of a refactor it would be to get MYA authentication going direct to the OIDC server instead of going via the API. This is because with the introduction of refresh tokens we're more than likely going to need to create the concept of an auth session in MYA. With this it would make sense that all of these concerns live within the UI. This PR demonstrates the changes that would be required.
The main change is in configuration -
type AuthProvider = { NAME: string; HOST_URL: string; IS_DIRECT: boolean; OFFLINE_ACCESS_ENABLED: boolean; TOKEN_URL: string; CLIENT_ID: string; CODE_CHALLENGE: string; CLIENT_SECRET: string; REQUIRES_STATE_FOR_AUTHORIZE: boolean; };We will need to update the redirect URLs if we go ahead with this refactor. We'll also need to enable offline access for OKTA and NHS Mail as part of enabling refresh tokens.
https://{MYA_ENV_DOMAIN}/manage-your-appointments/authinstead of one for each provider. OIDC typically works off the route being correct and not the absolute URL. In the interest of making our lives easier we should move to this format.Useful links
Fixes # (issue)
Checklist: