Skip to content
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

feat: add aurora entra id login #839

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

stuartmclean
Copy link

@stuartmclean stuartmclean commented Dec 23, 2023

Important notes:

This is not a complete reimplementation of the talent-connect auth process - it's merely a first step in that direction, presenting a working demonstration of several interactions with the Azure backend.

It should be safe to merge with the following feature flag: NX_ENTRA_ID_ENABLED=false although the other flags mentioned below should also be set in the production with at least empty string values to avoid issues during deployment.

Further steps required (should be done in separate tickets):

  • Extend the login steps to verify the user has an account registered in Salesforce and direct them to the correct page.
  • Enable Azure login option to existing users of connect
  • Enable Azure login option to existing users of talent-pool
  • Allow new users to register using Entra ID
  • Try to add additional methods of login that are not completely dependent on a user having a microsoft account (this should be possible through Entra ID as well).
  • Remove legacy auth implementation.

How to test:

This feature requires the following new env params:

NX_FRONTEND_URI="http://localhost:3000"
NX_ENTRA_ID_ENABLED=true
NX_ENTRA_ID_CLOUD_INSTANCE="https://login.microsoftonline.com"
NX_ENTRA_ID_TENANT_ID="https://login.microsoftonline.com"
NX_ENTRA_ID_CLIENT_ID="<get from Azure or PM me>"
NX_ENTRA_ID_CLIENT_SECRET="<get from Azure or PM me>"
entra-id-login-screen-recording.mov

Implementation summary:

When a customer clicks the "Log in with Microsoft" button:

  • they are redirected to the nestjs backend, which queries azure to...
  • form a unique URL, to which the nestjs backend redirects the user
  • the user logs in in azure using their own details
  • azure redirects the user to the nestjs backend
  • the nestjs backend calls azure to verify that the login was successful
connect-entra-id-auth-flow

@stuartmclean stuartmclean marked this pull request as draft December 23, 2023 14:18
@stuartmclean stuartmclean changed the title feat/add aurora entra id login feat: add aurora entra id login Dec 23, 2023
@stuartmclean stuartmclean marked this pull request as ready for review December 23, 2023 15:32
@helloanil helloanil closed this Jan 2, 2024
@helloanil helloanil reopened this Jan 2, 2024
system: {
loggerOptions: {
loggerCallback(logLevel, message, containsPii) {
if (!containsPii) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Such a cool trick. I wonder if AWS has a similar feature.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I was really happy to see this too. 😊

const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.use(json({ limit: '1mb' }))
app.use(urlencoded({ extended: true, limit: '1mb' }))
app.use(cookieParser())
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ericbolikowski ericbolikowski left a comment

Choose a reason for hiding this comment

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

Awesome progress, @stuartmclean! Great prototyping. I like your prototyping approach with feature flags so we can gradually roll this out.

I've left a few inline comments.

libs/shared-config/src/lib/config.ts Outdated Show resolved Hide resolved
apps/nestjs-api/src/auth-entra-id/entra-id.service.ts Outdated Show resolved Hide resolved
import { VerificationData } from './verification-data.interface'

@Injectable()
export class EntraIdLoginMiddleware implements NestMiddleware {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work here!

I've never used NestJS middleware. Is there a reason we're using it instead of a simple controller?

Copy link
Author

Choose a reason for hiding this comment

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

It seemed like the easiest way to protect this route and make it reusable for other routes.

Co-authored-by: Anıl Akarsu <anil@redi-school.org>
Signed-off-by: Stuart McLean <stuart.mclean@soundcloud.com>
Copy link

coderabbitai bot commented Jan 7, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@ericbolikowski ericbolikowski left a comment

Choose a reason for hiding this comment

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

❤️

@stuartmclean
Copy link
Author

❤️

😊 Thanks @ericbolikowski - I ran another manual test and discovered a flaw in my last commits - should be fixed by the most recent commit.

@@ -84,7 +84,7 @@ export const routes__loggedOut: RouteDefinition[] = [
{
path: '/front/login/entra-redirect',
component: () => {
window.location.href = `${NEST_API_URL}/auth/entra-id`
window.location.href = `${NEST_API_URL}/api/auth/entra-id`
Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartmclean What's the reason for this change? Is it a common practice to set a URL on the browser to what seems to be an API URL?

Copy link
Author

@stuartmclean stuartmclean Jan 23, 2024

Choose a reason for hiding this comment

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

Hi @helloanil This is a bit of a hack, I agree, but it doesn't actually display anything to the user and it's the only way I could make this work without setting up a whole different root url just for this one endpoint. Happy to hear other suggestions though. 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants