Giter VIP home page Giter VIP logo

Comments (6)

DarkLite1 avatar DarkLite1 commented on August 23, 2024

I found the -Silent switch which can be used to accommodate the desired behavior. The only issue is it cannot be combined with the the switch -IntegratedWindowsAuth. Ideally one would like to do this:

(0..50) | ForEach-Object {
    $msalParams = @{
        ClientId              = $azureClientId
        TenantId              = $azureTenantId
        IntegratedWindowsAuth = $true
        Scopes                = "https://outlook.office.com/EWS.AccessAsUser.All"
    }
    $token = Get-MsalToken @msalParams -Silent
}

Because that is not possible we now require two steps to get the same result:

  1. Acquire a token with -IntegratedWindowsAuth :
$msalParams = @{
    ClientId              = $azureClientId
    TenantId              = $azureTenantId
    IntegratedWindowsAuth = $true
    Scopes                = "https://outlook.office.com/EWS.AccessAsUser.All"
}
$token = Get-MsalToken @msalParams 
  1. Refresh the token:
$msalParams = @{
    ClientId              = $azureClientId
    TenantId              = $azureTenantId
    Scopes                = "https://outlook.office.com/EWS.AccessAsUser.All"
}
$token = Get-MsalToken @msalParams -Silent

Would it be possible to combine both steps?

from msal.ps.

jazuntee avatar jazuntee commented on August 23, 2024

Do you have requirement to only allow IntegratedWindowsAuth? Do you get the desired behavior when you remove the IntegratedWindowsAuth parameter? By default, the Get-MsalToken command will attempt a silent auth first, then IWA, and finally if all else fails it will do interactive in a web browser.

(0..50) | ForEach-Object {
    $msalParams = @{
        ClientId              = $azureClientId
        TenantId              = $azureTenantId
        Scopes                = "https://outlook.office.com/EWS.AccessAsUser.All"
    }
    $token = Get-MsalToken @msalParams
}

from msal.ps.

DarkLite1 avatar DarkLite1 commented on August 23, 2024

If I remember correctly I really need the switch IntegratedWindowsAuth = $true because in the Azure App Registration I have the following :

image

from msal.ps.

jazuntee avatar jazuntee commented on August 23, 2024

That switch determines what client application types the AAD service principal will accept which is either Public or Confidential.
https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-client-applications

The Get-MsalToken command will always use public client application object in MSAL when ClientSecret and ClientCertificate parameters are omitted.

from msal.ps.

DarkLite1 avatar DarkLite1 commented on August 23, 2024

In any case, I can tell you with certainty that when I did my test I really needed to add the -silent switch to have the token refreshed silently. If this was omitted it would not renew the token. Might have been my setup in Azure or something else, I just wanted you to know.

from msal.ps.

jazuntee avatar jazuntee commented on August 23, 2024

Just to clarify, MSAL will continue to return the same Access Token from the token cache until it expires or you specify the -ForceRefresh parameter.

I just tested without -IntegratedWindowsAuth or -Silent and it all appears to work silently as expected. Maybe this got fixed somewhere along the way but let me know if you are still unable to get it working.

## The same command does Integrated Windows Auth the first time and Silent for all subsequent call.
Get-MsalToken -ClientId $ClientId -TenantId mytenant.onmicrosoft.com

from msal.ps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.