Skip to content

Connect-GitHubAccount

SYNOPSIS

Connects to GitHub.

SYNTAX

UAT (Default)

Connect-GitHubAccount [-Mode <String>] [-Scope <String>] [-ClientID <String>] [-Owner <String>]
 [-Repo <String>] [-ApiVersion <String>] [-HostName <String>] [-Silent] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

PAT

Connect-GitHubAccount [-UseAccessToken] [-Owner <String>] [-Repo <String>] [-ApiVersion <String>]
 [-HostName <String>] [-Silent] [-ProgressAction <ActionPreference>] [<CommonParameters>]

Token

Connect-GitHubAccount -Token <Object> [-Owner <String>] [-Repo <String>] [-ApiVersion <String>]
 [-HostName <String>] [-Silent] [-ProgressAction <ActionPreference>] [<CommonParameters>]

App

Connect-GitHubAccount -ClientID <String> -PrivateKey <String> [-Owner <String>] [-Repo <String>]
 [-ApiVersion <String>] [-HostName <String>] [-Silent] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

Connects to GitHub using one of the following logon methods: - a personal access token - device code login (interactive user login) - a system access token (for GitHub Actions) - a GitHub App using JWT or installation access token

For device flow / device code login: PowerShell requests device and user verification codes and gets the authorization URL where you will enter the user verification code. In GitHub you will be asked to enter a user verification code at https://github.com/login/device. PowerShell will keep polling GitHub for the user authentication status. Once you have authorized the device, the app will be able to make API calls with a new access token.

EXAMPLES

EXAMPLE 1

Connect-GitHubAccount

Connects to GitHub using a device flow login. If the user has already logged in, the access token will be refreshed.

EXAMPLE 2

$env:GH_TOKEN = '***'
Connect-GitHubAccount

Connects to GitHub using the access token from environment variable, assuming unattended mode.

EXAMPLE 3

Connect-GitHubAccount -UseAccessToken
! Enter your personal access token: *************

User gets prompted for the access token and stores it in the context. The token is used when connecting to GitHub.

EXAMPLE 4

Connect-GitHubAccount -Mode 'OAuthApp' -Scope 'gist read:org repo workflow'

Connects to GitHub using a device flow login and sets the scope of the access token.

PARAMETERS

-Mode

Choose between authentication methods, either OAuthApp or GitHubApp. For more info about the types of authentication visit: Differences between GitHub Apps and OAuth apps

Type: String
Parameter Sets: UAT
Aliases:

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

-Scope

The scope of the access token, when using OAuth authentication. Provide the list of scopes as space-separated values. For more information on scopes visit: Scopes for OAuth apps

Type: String
Parameter Sets: UAT
Aliases:

Required: False
Position: Named
Default value: Gist read:org repo workflow
Accept pipeline input: False
Accept wildcard characters: False

-UseAccessToken

The user will be prompted to enter the token.

Type: SwitchParameter
Parameter Sets: PAT
Aliases:

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

-Token

An access token to use for authentication. Can be both a string or a SecureString. Supports both personal access tokens (PAT) and GitHub App installation access tokens (IAT). Example: 'ghp_1234567890abcdef' Example: 'ghs_1234567890abcdef'

Type: Object
Parameter Sets: Token
Aliases:

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

-ClientID

The client ID for the GitHub App to use for authentication.

Type: String
Parameter Sets: UAT
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Type: String
Parameter Sets: App
Aliases:

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

-PrivateKey

The private key for the GitHub App when authenticating as a GitHub App.

Type: String
Parameter Sets: App
Aliases:

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

-Owner

Set the default owner to use in commands.

Type: String
Parameter Sets: (All)
Aliases: Org, Organization

Required: False
Position: Named
Default value: $env:GITHUB_REPOSITORY_OWNER
Accept pipeline input: False
Accept wildcard characters: False

-Repo

Set the default repository to use in commands.

Type: String
Parameter Sets: (All)
Aliases: Repository

Required: False
Position: Named
Default value: $env:GITHUB_REPOSITORY_NAME
Accept pipeline input: False
Accept wildcard characters: False

-ApiVersion

API version used for API requests.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 2022-11-28
Accept pipeline input: False
Accept wildcard characters: False

-HostName

The host to connect to. Can use $env:GITHUB_SERVER_URL to set the host, as the protocol is removed automatically. Example: github.com, github.enterprise.com, msx.ghe.com

Type: String
Parameter Sets: (All)
Aliases: Server, Host

Required: False
Position: Named
Default value: $env:GITHUB_SERVER_URL ?? 'github.com'
Accept pipeline input: False
Accept wildcard characters: False

-Silent

Suppresses the output of the function.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: s, q, Quiet

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

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

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

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Void

NOTES

Authenticating to the REST API