< Back
New-AzureRMRESTApiAuthenticationToken
Post
NAME New-AzureRMRESTApiAuthenticationToken
SYNOPSIS
Enables you to get Azure authentication token
SYNTAX
New-AzureRMRESTApiAuthenticationToken [-TenantId] <String> [-ApplicationId] <String> [-ApplicationKey] <String>
[-SubscriptionId] <String> [-Resource] <Object> [<CommonParameters>]
DESCRIPTION
Inorder to do CRUD oprations on Azure using REST API you firstly you should obtain the autheitication token post
which you can generate header from it and so on..
This command helps you to get the authentication token
PARAMETERS
-TenantId <String>
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ApplicationId <String>
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ApplicationKey <String>
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SubscriptionId <String>
Required? true
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Resource <Object>
Required? true
Position? 5
Default value
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
1. TenantId
2. ApplicationId
3. ApplicationKey
4. SubscriptionId
OUTPUTS
PSCustomObject
NOTES
Probably this notes helps you get the data points to form the command.
---------------------------------------------------------------------------------------------------------------
-------------------------------------
| Parameter | How to get it
---------------------------------------------------------------------------------------------------------------
-------------------------------------
| Tenant Id | Azure Path = search for 'Azure Active Directory'->'Properties'->'Directory ID'
| |
| Application Id | Auzre Path = search for 'Azure Active Directory'->'App registrations'->search for the
appliaction you created/ have access
| | and should be type of 'Web app / API'->copy 'Application ID'
| |
| Application Key | Azure Path = I cannot help you should have copied the key when you create the new
application registration
| |
| Subscription Id | Azure Path = search for 'Subscriptions'->Copy the 'Subscription ID' of the subscription
on which you want to operate
---------------------------------------------------------------------------------------------------------------
-------------------------------------
Okey, lets say you got toke id so whats next...hmm, here you go with one example
1. Create header
----------------
$Headers.Add("Authorization","$($Token.token_type) "+ " " + "$($Token.access_token)")
2. For example, lets fetch list of resource groups
--------------------------------------------------
$ResourceGroups = Invoke-RestMethod -Method Get -Uri $ResourceGroupApiUri -Headers $Headers
Enjoy
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$token = New-AzureRMRESTApiAuthenticationToken -TenantId 'xxxxxxxx-238f-xxxx-xxxx-xxxxxxxxxxxx'
-ApplicationId '64b2470d-a3d8-45ff-9123-4faf3ced0238' -ApplicationKey
'1234567890dajQVUL7lJ2jcp5AbUFdtuhlMAiPeAJ2E=' -SubscriptionId 'xxxxxxxx-238f-xxxx-xxxx-xxxxxxxxxxxx' -Resource
(https://graph.microsoft.com/ (or) https://management.core.windows.net/)
PS C:\\$token
token_type : Bearer
expires_in : 3599
ext_expires_in : 0
expires_on : 1540454626
not_before : 1540450726
resource : https://graph.microsoft.com
access_token : eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imk2bEdrM0ZaenhSY1ViMkMzbkVRN3N5SEpsWSIsImtpZCI6Imk2bE
drM0ZaenhSY1ViMkMzbkVRN3N
5SEpsWSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5
kb3dzLm5ldC84ZDg5NGMyY
i0yMzhmLTQ5MGItddOGRkMS1kO4OThjNWJmODMvIiwiaWF0IjoxNTQwNDUwNzI2LCJuYmYiOjE1NDA0NTA3MjYsImV4cCI6MTU0MD
Q1NDYyNiwiYWlvIjoiNDJS
Z1lBait0bTVwWVNaNzllsshtdDZ1UG85ckFBPT0iLCJhcHBpZCI6IjY0YjI0NzBkLWEzZDgtNDVmZi05MTIzLTRmYWYzY2VkMDIzO
CIsImFwcGlkYWNyIjoiMSI
sImlkcCI6Imh0dHBzOidd8sczLndpbmRvd3MubmV0LzhkODk0YzJiLTIzOGYtNDkwYi04ZGQxLWQ5Mzg5OGM1YmY4My8iLCJvaWQi
OiJhOWFlZWRhNC1hMWU5LT
QwOTktOWVhNy1mNzc1sshjZTY4ZWYiLCJzdWIiOiJhOWFlZWRhNC1hMWU5LTQwOTktOWVhNy1mNzc1ODhjZTY4ZWYiLCJ0aWQiOiI
4ZDg5NGMyYi0yMzhmLTQ5M
GItOGRkMS1kOTM4OThjNWJmODMiLCJ1dGkiOiJBTzhGczFSRk9VYVNPRkY5S1FRaEFRIiwidmVyIjoiMS4wIn0.Pse_WldgQ5K35W
zFRRM2gac_AGpZUFGOUhmM
Lr_yi4C0Uk7RzLF9ZdxUb8O-ppMjN4-m9gRXCwmF9KrUbNiMNsPGoQiabS0hYjrVj_W5VSBIP5VoTSYBB1i6y14vULdSeOVWB4Ftv
Dh99ml0kaLFOh3WZblLbrz
c5wyqx4HXWjkXw6Gb_MFAh69WJqC2sif6k7Yh43DdHhzSX9f-C8ybGcAK8Ez9-aMFpR0jDkBKZKHGc_s-qFh6Wcq72-Hb1J4eOgSF
v_89IPy2okxqhZsBviP4d1
L35nMAKmmhG1qrEmcLwalRYqECmHrrTbfkwGJyi2zX2__de11Gww5NeJcecA
RELATED LINKS
https://docs.microsoft.com/en-us/azure/ ... ate-an-azu
re-active-directory-application
SYNOPSIS
Enables you to get Azure authentication token
SYNTAX
New-AzureRMRESTApiAuthenticationToken [-TenantId] <String> [-ApplicationId] <String> [-ApplicationKey] <String>
[-SubscriptionId] <String> [-Resource] <Object> [<CommonParameters>]
DESCRIPTION
Inorder to do CRUD oprations on Azure using REST API you firstly you should obtain the autheitication token post
which you can generate header from it and so on..
This command helps you to get the authentication token
PARAMETERS
-TenantId <String>
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ApplicationId <String>
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ApplicationKey <String>
Required? true
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-SubscriptionId <String>
Required? true
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Resource <Object>
Required? true
Position? 5
Default value
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
1. TenantId
2. ApplicationId
3. ApplicationKey
4. SubscriptionId
OUTPUTS
PSCustomObject
NOTES
Probably this notes helps you get the data points to form the command.
---------------------------------------------------------------------------------------------------------------
-------------------------------------
| Parameter | How to get it
---------------------------------------------------------------------------------------------------------------
-------------------------------------
| Tenant Id | Azure Path = search for 'Azure Active Directory'->'Properties'->'Directory ID'
| |
| Application Id | Auzre Path = search for 'Azure Active Directory'->'App registrations'->search for the
appliaction you created/ have access
| | and should be type of 'Web app / API'->copy 'Application ID'
| |
| Application Key | Azure Path = I cannot help you should have copied the key when you create the new
application registration
| |
| Subscription Id | Azure Path = search for 'Subscriptions'->Copy the 'Subscription ID' of the subscription
on which you want to operate
---------------------------------------------------------------------------------------------------------------
-------------------------------------
Okey, lets say you got toke id so whats next...hmm, here you go with one example
1. Create header
----------------
$Headers.Add("Authorization","$($Token.token_type) "+ " " + "$($Token.access_token)")
2. For example, lets fetch list of resource groups
--------------------------------------------------
$ResourceGroups = Invoke-RestMethod -Method Get -Uri $ResourceGroupApiUri -Headers $Headers
Enjoy
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$token = New-AzureRMRESTApiAuthenticationToken -TenantId 'xxxxxxxx-238f-xxxx-xxxx-xxxxxxxxxxxx'
-ApplicationId '64b2470d-a3d8-45ff-9123-4faf3ced0238' -ApplicationKey
'1234567890dajQVUL7lJ2jcp5AbUFdtuhlMAiPeAJ2E=' -SubscriptionId 'xxxxxxxx-238f-xxxx-xxxx-xxxxxxxxxxxx' -Resource
(https://graph.microsoft.com/ (or) https://management.core.windows.net/)
PS C:\\$token
token_type : Bearer
expires_in : 3599
ext_expires_in : 0
expires_on : 1540454626
not_before : 1540450726
resource : https://graph.microsoft.com
access_token : eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imk2bEdrM0ZaenhSY1ViMkMzbkVRN3N5SEpsWSIsImtpZCI6Imk2bE
drM0ZaenhSY1ViMkMzbkVRN3N
5SEpsWSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuY29yZS53aW5kb3dzLm5ldC8iLCJpc3MiOiJodHRwczovL3N0cy53aW5
kb3dzLm5ldC84ZDg5NGMyY
i0yMzhmLTQ5MGItddOGRkMS1kO4OThjNWJmODMvIiwiaWF0IjoxNTQwNDUwNzI2LCJuYmYiOjE1NDA0NTA3MjYsImV4cCI6MTU0MD
Q1NDYyNiwiYWlvIjoiNDJS
Z1lBait0bTVwWVNaNzllsshtdDZ1UG85ckFBPT0iLCJhcHBpZCI6IjY0YjI0NzBkLWEzZDgtNDVmZi05MTIzLTRmYWYzY2VkMDIzO
CIsImFwcGlkYWNyIjoiMSI
sImlkcCI6Imh0dHBzOidd8sczLndpbmRvd3MubmV0LzhkODk0YzJiLTIzOGYtNDkwYi04ZGQxLWQ5Mzg5OGM1YmY4My8iLCJvaWQi
OiJhOWFlZWRhNC1hMWU5LT
QwOTktOWVhNy1mNzc1sshjZTY4ZWYiLCJzdWIiOiJhOWFlZWRhNC1hMWU5LTQwOTktOWVhNy1mNzc1ODhjZTY4ZWYiLCJ0aWQiOiI
4ZDg5NGMyYi0yMzhmLTQ5M
GItOGRkMS1kOTM4OThjNWJmODMiLCJ1dGkiOiJBTzhGczFSRk9VYVNPRkY5S1FRaEFRIiwidmVyIjoiMS4wIn0.Pse_WldgQ5K35W
zFRRM2gac_AGpZUFGOUhmM
Lr_yi4C0Uk7RzLF9ZdxUb8O-ppMjN4-m9gRXCwmF9KrUbNiMNsPGoQiabS0hYjrVj_W5VSBIP5VoTSYBB1i6y14vULdSeOVWB4Ftv
Dh99ml0kaLFOh3WZblLbrz
c5wyqx4HXWjkXw6Gb_MFAh69WJqC2sif6k7Yh43DdHhzSX9f-C8ybGcAK8Ez9-aMFpR0jDkBKZKHGc_s-qFh6Wcq72-Hb1J4eOgSF
v_89IPy2okxqhZsBviP4d1
L35nMAKmmhG1qrEmcLwalRYqECmHrrTbfkwGJyi2zX2__de11Gww5NeJcecA
RELATED LINKS
https://docs.microsoft.com/en-us/azure/ ... ate-an-azu
re-active-directory-application