Skip to content

Commit 036e74a

Browse files
🩹 [Patch]: Update the examples for how to connect using the module (#489)
## Description This pull request updates the `examples/Connecting.ps1` script to clarify and expand the usage examples for GitHub connection methods, including new authentication flows and improved documentation. The changes also make some minor corrections to comments and example commands related to context management. Authentication and connection improvements: * Added examples for connecting to GitHub programmatically using a token and clarified support for both fine-grained and classic PATs in the `Connect-GitHub` command. * Added new examples for connecting using a GitHub App with a private key stored in Azure Key Vault, including the use of `Connect-GitHubApp` for organizational contexts. * Improved comments for OAuth App, Device Flow, and PAT authentication flows to clarify best practices and supported scenarios. Context and profile management: * Updated comments to clarify that context names can be tab-completed and corrected a typo in the `Switch-GitHubContext` example (`Switch-GitHubCwontext`). ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --------- Co-authored-by: Copilot <[email protected]>
1 parent 2dff5b7 commit 036e74a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

examples/Connecting.ps1

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@ Connect-GitHub
77

88
# Log on to a specific instance of GitHub (enterprise)
99
Connect-GitHub -Host 'msx.ghe.com'
10-
Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts should be selectable/overrideable on any call
10+
Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts are selectable/overrideable on any call
1111

12-
# Connect to GitHub interactively using OAuth App and Device Flow (should not use this, should we even support it?)
12+
# Connect to GitHub interactively using OAuth App and Device Flow.
1313
Connect-GitHub -Mode 'OAuthApp' -Scope 'gist read:org repo workflow'
1414

15-
# Connect to GitHub interactively using less desired PAT flow
15+
# Connect to GitHub interactively using less desired PAT flow, supports both fine-grained and classic PATs
1616
Connect-GitHub -UseAccessToken
1717

18+
# Connect to GitHub programatically (GitHub App Installation Access Token or PAT)
19+
Connect-GitHub -Token ***********
20+
1821
# Connect to GitHub programatically (GitHub Actions)
1922
Connect-GitHub # Looks for the GITHUB_TOKEN variable
2023

21-
# Connect to GitHub programatically (GitHub App, for GitHub Actions or external applications, JWT login)
24+
# Connect using a GitHub App and its private key (local signing of JWT)
2225
Connect-GitHub -ClientID '<client_id>' -PrivateKey '<private_key>'
2326

24-
# Connect to GitHub programatically (GitHub App Installation Access Token or PAT)
25-
Connect-GitHub -Token ***********
27+
# Connect using a GitHub App and the Key vault for signing the JWT.
28+
# Prereq: The private key is stored in an Azure Key Vault and the shell has an authenticated Azure PowerShell or Azure CLI session
29+
$ClientID = 'Iv23lieHcDQDwVV3alK1'
30+
$KeyVaultKeyReference = 'https://psmodule-test-vault.vault.azure.net/keys/psmodule-ent-app'
31+
Connect-GitHub -ClientID $ClientID -KeyVaultKeyReference $KeyVaultKeyReference
32+
Connect-GitHubApp -Organization 'dnb-tooling'
33+
2634

2735
###
2836
### Contexts / Profiles
@@ -37,14 +45,12 @@ Get-GitHubContext -ListAvailable
3745
# Returns a specific context, autocomplete the name.
3846
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
3947

40-
# Take a name dynamically from Get-GitHubContext? Autocomplete the name
48+
# Take a name dynamically from Get-GitHubContext? tab-complete the name
4149
Switch-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
4250

4351
# Set a specific context as the default context using pipeline
4452
'msx.ghe.com/MariusStorhaug' | Switch-GitHubContext
4553

46-
Get-GitHubContext -Context 'github.com/MariusStorhaug' | Switch-GitHubContext
47-
4854
# Abstraction layers on GitHubContexts
4955
Get-GitHubContext -Context 'msx.ghe.com/MariusStorhaug'
5056

0 commit comments

Comments
 (0)