< Back
Get-GoogleOAuth2Code
Post
NAME Get-GoogleOAuth2Code
SYNOPSIS
Gets an authorization code for specified scopes to be granted Google OAuth2 credentials.
SYNTAX
Get-GoogleOAuth2Code [-ClientId] <String> [[-Email] <String>] [[-AccessType] <String>] [[-ResponseType] <String>]
[-NoPrompt] [<CommonParameters>]
DESCRIPTION
This cmdlet initiates the user approval for access to data and opens a browser window for the user to
login and provide consent to the access. After approval, the browser will present an authorization code
that should be pasted back into the prompt presented to the user. The code is sent out the pipeline, which
should be supplied to Get-GoogleOAuth2Token in order to get Google OAuth2 bearer tokens.
PARAMETERS
-ClientId <String>
The supplied client id for OAuth.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Email <String>
The user's GSuite/Google user email to provide as a login hint to the login and consent page.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-AccessType <String>
Indicates the module can refresh access tokens when the user is not present at the browser. This value
instructs the Google authorization server to return a refresh token and an access token the first time
that the cmdlet exchages an authorization code for tokens. You should always specify "offline", which
is the default.
Required? false
Position? 3
Default value offline
Accept pipeline input? false
Accept wildcard characters? false
-ResponseType <String>
How the Google Authorization server returns the code:
Setting to "token" instructs the Google Authorization Server to return the access token as a name=value
pair in the hash (#) fragment of the URI to which the user is redirected after completing the authorization
process.
You must specify "online" as the AccessType with this setting and provide an actual redirect url.
Setting to "code" instructs the Google Authorization Server to return the access code as an element in the web
browser
that can be copy and pasted into PowerShell.
You should always specify "code" for this cmdlet, which is the default.
Required? false
Position? 4
Default value code
Accept pipeline input? false
Accept wildcard characters? false
-NoPrompt [<SwitchParameter>]
Indicates that the user receives no prompt in the web browser, which will likely result in a failed attempt or
an access denied error. You
shouldn't specify this parameter.
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
None
OUTPUTS
System.String
NOTES
AUTHOR: Michael Haken
LAST UPDATE: 1/12/2018
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Code = Get-GoogleOAuth2Code -ClientId $Id -ClientSecret $Secret -Email john.smith@google.com -Scope
"admin.directory.group.readonly"
Gets an authorization code for the user to be able to exchange it for a long-term access token with the ability to
have
read-only access to groups in GSuite through the Google Directory API.
RELATED LINKS
SYNOPSIS
Gets an authorization code for specified scopes to be granted Google OAuth2 credentials.
SYNTAX
Get-GoogleOAuth2Code [-ClientId] <String> [[-Email] <String>] [[-AccessType] <String>] [[-ResponseType] <String>]
[-NoPrompt] [<CommonParameters>]
DESCRIPTION
This cmdlet initiates the user approval for access to data and opens a browser window for the user to
login and provide consent to the access. After approval, the browser will present an authorization code
that should be pasted back into the prompt presented to the user. The code is sent out the pipeline, which
should be supplied to Get-GoogleOAuth2Token in order to get Google OAuth2 bearer tokens.
PARAMETERS
-ClientId <String>
The supplied client id for OAuth.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Email <String>
The user's GSuite/Google user email to provide as a login hint to the login and consent page.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-AccessType <String>
Indicates the module can refresh access tokens when the user is not present at the browser. This value
instructs the Google authorization server to return a refresh token and an access token the first time
that the cmdlet exchages an authorization code for tokens. You should always specify "offline", which
is the default.
Required? false
Position? 3
Default value offline
Accept pipeline input? false
Accept wildcard characters? false
-ResponseType <String>
How the Google Authorization server returns the code:
Setting to "token" instructs the Google Authorization Server to return the access token as a name=value
pair in the hash (#) fragment of the URI to which the user is redirected after completing the authorization
process.
You must specify "online" as the AccessType with this setting and provide an actual redirect url.
Setting to "code" instructs the Google Authorization Server to return the access code as an element in the web
browser
that can be copy and pasted into PowerShell.
You should always specify "code" for this cmdlet, which is the default.
Required? false
Position? 4
Default value code
Accept pipeline input? false
Accept wildcard characters? false
-NoPrompt [<SwitchParameter>]
Indicates that the user receives no prompt in the web browser, which will likely result in a failed attempt or
an access denied error. You
shouldn't specify this parameter.
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
None
OUTPUTS
System.String
NOTES
AUTHOR: Michael Haken
LAST UPDATE: 1/12/2018
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>$Code = Get-GoogleOAuth2Code -ClientId $Id -ClientSecret $Secret -Email john.smith@google.com -Scope
"admin.directory.group.readonly"
Gets an authorization code for the user to be able to exchange it for a long-term access token with the ability to
have
read-only access to groups in GSuite through the Google Directory API.
RELATED LINKS