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

Using MSAL for admin consent authentication #6384

Closed
shon2789 opened this issue Aug 24, 2023 · 2 comments
Closed

Using MSAL for admin consent authentication #6384

shon2789 opened this issue Aug 24, 2023 · 2 comments
Assignees
Labels
msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.

Comments

@shon2789
Copy link

Core Library

MSAL.js (@azure/msal-browser)

Core Library Version

3.0.2

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

2.02

Public or Confidential Client?

Public

Description

I want to let the user authenticate with a pop-up and not redirecting him to Microsoft site from the current page that he is on.
So I tried to implement pop-up authentication for admin consent with MSAL, but I didn't find a way to make the configuration support admin consent.

This is our current configuration, I'd like to achieve something similar using MSAL-react.

I'm currently using an admin consent flow to acquire consent from customers, afterwards we are using the https://login.microsoftonline.com/$%7BtenantId%7D/oauth2/v2.0/token to generate access tokens using the customer's tenantId

Our current consent part, looks like this:

const url = `https://login.microsoftonline.com/common/adminconsent?`
  const params = new URLSearchParams()
  params.append('prompt', 'admin_consent')
  params.append('redirect_uri', encodeURI(getCallbackUrl(app)))
  params.append('response_type', 'code')
  params.append('client_id', clientId)
  params.append('state', state || '')

  return url + params 

When we have request redirected from Microsoft we're getiing the tenantId and we're able to generate a token using that tenantId.

Does MSAL support admin consent authentication?
If so, can you direct me to how to configure it properly?

MSAL Configuration

{
  auth: {
    clientId: 'clientId',
    authority: `https://login.microsoftonline.com/common`,
    redirectUri: 'redirectUri'
  }
}

Relevant Code Snippets

const TestComponent = () => {
  const { instance } = useMsal()
  const loginRequest: PopupRequest = {
    scopes: [
      // 'Application.ReadWrite.OwnedBy',
      'Application.ReadWrite.All',
      'Directory.Read.All',
      'User.Read.All',
      'Sites.ReadWrite.All',
      'Files.ReadWrite.All',
      // 'ActivityFeed.ReadDlp',
      // 'ActivityFeed.Read',
      'Sites.FullControl.All'
    ],
    state: 'someString',
    prompt: 'consent'
  }

  const handleLogin = async () => {
    try {
      const test = await instance.acquireTokenPopup(loginRequest)
      console.log(test)
    } catch (e) {
      console.log(e)
    }
  }
  return <DcButton onClick={() => handleLogin()}>This is test</DcButton>
}

Identity Provider

Azure AD / MSA

Source

External (Customer)

@shon2789 shon2789 added the question Customer is asking for a clarification, use case or information. label Aug 24, 2023
@github-actions github-actions bot added msal-browser Related to msal-browser package msal-react Related to @azure/msal-react public-client Issues regarding PublicClientApplications labels Aug 24, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Aug 24, 2023
@lalimasharda
Copy link
Contributor

Hey @shon2789 , can you check if you have you setup admin consent for these scopes on Azure Portal in your app registration? Please take a look at this issue for reference.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Aug 25, 2023
@microsoft-github-policy-service
Copy link
Contributor

@shon2789 This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

@microsoft-github-policy-service microsoft-github-policy-service bot added the no-issue-activity Issue author has not responded in 5 days label Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-browser Related to msal-browser package msal-react Related to @azure/msal-react Needs: Author Feedback Awaiting response from issue author no-issue-activity Issue author has not responded in 5 days public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

2 participants