Comments (6)
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:
- Acquire a token with
-IntegratedWindowsAuth
:
$msalParams = @{
ClientId = $azureClientId
TenantId = $azureTenantId
IntegratedWindowsAuth = $true
Scopes = "https://outlook.office.com/EWS.AccessAsUser.All"
}
$token = Get-MsalToken @msalParams
- 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.
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.
If I remember correctly I really need the switch IntegratedWindowsAuth = $true
because in the Azure App Registration I have the following :
from msal.ps.
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.
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.
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)
- IntegratedWindowsAuth example? HOT 4
- MSAL token provided only works with MS Graph HOT 1
- Support WAM as an Authentication Method
- Get-MsalToken fails to launch interactive authentication prompt from Windows Terminal HOT 4
- replace load of PS1 files in psd1 by a main psm1 loading the ps1 HOT 3
- -Scope or -Scopes? HOT 1
- Import Module fails when home./config is not present HOT 1
- Missing Get-MsalToken in version 4.37.0.0 HOT 1
- New-MsalClientApplication : Cannot convert argument "builder" HOT 4
- MSAL.PS in Azure Automation with 7.2 Runbook
- Get-MsalToken fails for some users, references a .NET in error message. HOT 3
- New-MsalClientApplication : Cannot convert argument "builder" HOT 4
- "Microsoft.Identity.Client.dll" conflicts w/same assembly from ExchangeOnlineManagement module HOT 3
- I get this error with Select-MsalClientApplication.ps1
- Import-Module MSAL.PS retrieve errors
- Primary refresh token missing in WebView2, unable to authenticate HOT 4
- Import-Module : Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Microsoft.Identity.Client.4.37.0\net45\Microsoft.Identity.Client.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
- Use with different ResourceUri's? HOT 2
- Unable to convert .cert file to type X509Certificates.X509Certificate2
- Version of Microsoft.Identity.Client is significantly dated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msal.ps.