Invoke D365LcsApiRefreshToken - FH-Inway/d365fo.tools GitHub Wiki
Refresh the token for lcs communication
Invoke-D365LcsApiRefreshToken -ClientId <String> [-InputObject <PSObject>] [-EnableException]
[<CommonParameters>]
Invoke-D365LcsApiRefreshToken -ClientId <String> -RefreshToken <String> [-EnableException] [<CommonParameters>]
Invoke the refresh logic that refreshes the token object based on the ClientId and RefreshToken
Invoke-D365LcsApiRefreshToken -ClientId "9b4f4503-b970-4ade-abc6-2c086e4c4929" -RefreshToken "Tsdljfasfe2j32324"
This will refresh an OAuth 2.0 access token, and obtain a (new) valid OAuth 2.0 access token from Azure Active Directory. The ClientId "9b4f4503-b970-4ade-abc6-2c086e4c4929" is used in the OAuth 2.0 "Refresh Token" Grant Flow to authenticate. The RefreshToken "Tsdljfasfe2j32324" is used to prove to Azure Active Directoy that we are allowed to obtain a new valid Access Token.
$temp = Get-D365LcsApiToken -LcsApiUri "https://lcsapi.eu.lcs.dynamics.com" -ClientId "9b4f4503-b970-4ade-abc6-2c086e4c4929" -Username "[email protected]" -Password "TopSecretPassword"
PS C:\> $temp = Invoke-D365LcsApiRefreshToken -ClientId "9b4f4503-b970-4ade-abc6-2c086e4c4929" -InputObject $temp
This will refresh an OAuth 2.0 access token, and obtain a (new) valid OAuth 2.0 access token from Azure Active Directory. This will obtain a new token object from the Get-D365LcsApiToken cmdlet and store it in $temp. Then it will pass $temp to the Invoke-D365LcsApiRefreshToken along with the ClientId "9b4f4503-b970-4ade-abc6-2c086e4c4929". The new token object will be save into $temp.
Get-D365LcsApiConfig | Invoke-D365LcsApiRefreshToken | Set-D365LcsApiConfig
This will refresh an OAuth 2.0 access token, and obtain a (new) valid OAuth 2.0 access token from Azure Active Directory. This will fetch the current LCS API details from Get-D365LcsApiConfig. The output from Get-D365LcsApiConfig is piped directly to Invoke-D365LcsApiRefreshToken, which will fetch a new token object. The new token object is piped directly into Set-D365LcsApiConfig, which will save the needed details into the configuration store.
The Azure Registered Application Id / Client Id obtained while creating a Registered App inside the Azure Portal
Type: String
Parameter Sets: Object
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Type: String
Parameter Sets: Simple
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The Refresh Token that you want to use for the authentication process
Type: String
Parameter Sets: Simple
Aliases: Token, refresh_token
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
The entire object that you received from the Get-D365LcsApiToken command, which contains the needed RefreshToken
Type: PSObject
Parameter Sets: Object
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This parameters disables user-friendly warnings and enables the throwing of exceptions This is less user friendly, but allows catching exceptions in calling scripts
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Tags: LCS, API, Token, BearerToken
Author: Mötz Jensen (@Splaxi)