< Back

Get-ADALAccessToken

Sat Jan 18, 2020 11:37 am

NAME Get-ADALAccessToken



SYNOPSIS

Acquires OAuth 2.0 AccessToken from Azure Active Directory (AAD)





SYNTAX

Get-ADALAccessToken -AuthorityName <String> -ClientId <String> -ResourceId <String> -UserName <String> -Password

<String> [<CommonParameters>]



Get-ADALAccessToken -AuthorityName <String> -ClientId <String> -ResourceId <String> -RedirectUri <String>

[-ForcePromptSignIn] [<CommonParameters>]





DESCRIPTION

The Get-AccessToken cmdlet lets you acquire OAuth 2.0 AccessToken from Azure Active Directory (AAD)

by using Active Directory Authentication Library (ADAL).



There are two ways to get AccessToken



1. You can pass UserName and Password to avoid SignIn Prompt.

2. You can pass RedirectUri to use SignIn prompt.



If you want to use different credential by using SignIn Prompt, use ForcePromptSignIn.

Use Get-Help Get-AccessToken -Examples for more detail.





PARAMETERS

-AuthorityName <String>

Azure Active Directory Name or Guid. i.e.)contoso.onmicrosoft.com



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ClientId <String>

A registerered ClientId as application to the Azure Active Directory.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ResourceId <String>

A Id of service (resource) to consume.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-UserName <String>

A username to login to Azure Active Directory.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Password <String>

A password for UserName



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-RedirectUri <String>

A registered RedirectUri as application to the Azure Active Directory.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ForcePromptSignIn [<SwitchParameter>]

Indicate to force prompting for signin in.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-ADALAccessToken -AuthorityName contoso.onmicrosoft.com -ClientId 8f710b23-d3ea-4dd3-8a0e-c5958a6bc16d

-ResourceId https://analysis.windows.net/powerbi/api -RedirectUri $redirectUri



This example acquire accesstoken by using RedirectUri from contoso.onmicrosoft.com Azure Active Directory for

PowerBI service.

It will only prompt you to sign in for the first time, or when cache is expired.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-ADALAccessToken -AuthorityName contoso.onmicrosoft.com -ClientId 8f710b23-d3ea-4dd3-8a0e-c5958a6bc16d

-ResourceId https://analysis.windows.net/powerbi/api -RedirectUri $redirectUri -ForcePromptSignIn



This example acquire accesstoken by using RedirectUri from contoso.onmicrosoft.com Azure Active Directory for

PowerBI service.

It always prompt you to sign in.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Get-ADALAccessToken -AuthorityName contoso.onmicrosoft.com -ClientId 8f710b23-d3ea-4dd3-8a0e-c5958a6bc16d

-ResourceId https://analysis.windows.net/powerbi/api -UserName user1@contoso.onmicrosoft.com -Password password



This example acquire accesstoken by using UserName/Password from contoso.onmicrosoft.com Azure Active Directory

for PowerBI service.











RELATED LINKS