Table of Contents

Get-PnPAccessToken

SYNOPSIS

Returns the current Microsoft Graph OAuth Access token. If a Resource Type Name or Resource URL is specified, it will fetch the access token of the specified resource.

SYNTAX

Graph Token

Get-PnPAccessToken [-ResourceTypeName] [-Decoded] [-Scopes] [-Connection <PnPConnection>]

Specific resource by type

Get-PnPAccessToken -ResourceTypeName <ResourceTypeName> [-Decoded] [-Scopes] [-Connection <PnPConnection>]

Specific resource by URL

Get-PnPAccessToken -ResourceUrl <String> [-Decoded] [-Scopes] [-Connection <PnPConnection>]

List Permission Scopes in current access token

Get-PnPAccessToken -ListPermissionScopes [-ResourceTypeName <String>]

DESCRIPTION

Returns the OAuth 2.0 Access Token.

EXAMPLES

EXAMPLE 1

Get-PnPAccessToken

Gets the OAuth 2.0 Access Token to consume the Microsoft Graph API

EXAMPLE 2

Get-PnPAccessToken -Decoded

Gets the OAuth 2.0 Access Token to consume the Microsoft Graph API and shows the token with its content decoded

EXAMPLE 3

Get-PnPAccessToken -ResourceTypeName SharePoint

Gets the OAuth 2.0 Access Token to consume the SharePoint APIs and perform CSOM operations.

EXAMPLE 4

Get-PnPAccessToken -ResourceTypeName ARM

Gets the OAuth 2.0 Access Token to consume the Azure Resource Manager APIs and perform related operations. In PnP, you can use them in cmdlets related to Flow and PowerPlatform etc.

EXAMPLE 5

Get-PnPAccessToken -ResourceUrl "https://management.azure.com/.default"

Gets the OAuth 2.0 Access Token to consume the SharePoint APIs and perform CSOM operations.

EXAMPLE 6

Get-PnPAccessToken -ListPermissionScopes

Lists the current permission scopes for the Microsoft Graph API on the access token. Specify -ResourceTypeName to list permissions for other resource types, like SharePoint.

PARAMETERS

-ResourceTypeName

Specify the Resource Type for which you want the access token. If not specified, it will by default return a Microsoft Graph access token.

Type: ResourceTypeName
Parameter Sets: Resource Type Name, Resource Type Name (decoded)
Accepted values: Graph, SharePoint, ARM

Required: False
Position: Named
Default value: Graph
Accept pipeline input: False
Accept wildcard characters: False

-ResourceUrl

Specify the Resource URL for which you want the access token, i.e. https://graph.microsoft.com/.default. If not specified, it will by default return a Microsoft Graph access token.

Type: String
Parameter Sets: Resource Url, Resource Url (decoded)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Decoded

Returns the details from the access token in a decoded manner

Type: SwitchParameter
Parameter Sets: Resource Type Name (decoded), Resource Url (decoded)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Connection

Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

Type: PnPConnection
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Scopes

The scopes to retrieve the token for. Defaults to AllSites.FullControl

Type: String[]
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ListPermissionScopes

If specified the current permission scopes on the access token will be listed

Type: SwitchParameter
Parameter Sets: List Permission Scopes

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Microsoft 365 Patterns and Practices