diff --git a/JiraPS/Public/New-JiraSession.ps1 b/JiraPS/Public/New-JiraSession.ps1 index 1c07b2e7..3688f0be 100644 --- a/JiraPS/Public/New-JiraSession.ps1 +++ b/JiraPS/Public/New-JiraSession.ps1 @@ -3,7 +3,7 @@ function New-JiraSession { [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')] param( - [Parameter( Mandatory )] + [Parameter( )] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential, @@ -29,8 +29,8 @@ function New-JiraSession { Method = "GET" Headers = $Headers StoreSession = $true - Credential = $Credential } + if ($Credential) { $parameter.Add('Credential',$Credential) } Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter" $result = Invoke-JiraMethod @parameter diff --git a/docs/en-US/about_JiraPS_Authentication.md b/docs/en-US/about_JiraPS_Authentication.md index a5fb7ba9..cea262f4 100644 --- a/docs/en-US/about_JiraPS_Authentication.md +++ b/docs/en-US/about_JiraPS_Authentication.md @@ -56,6 +56,8 @@ the email address and the API token must be used. > with **Cloud Servers** to **always** use API Tokens. > More information in the [Deprecation notice](https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/). +Some implementations of Jira Server (on-premise) might not be able to use HTTP Basic authentication method noted above when using API tokens. For this, you may need to create a new Jira session using `New-JiraSession` and pass a custom Authorization header. + _More information on the API tokens and how to create one can be found at:_ __ @@ -85,6 +87,19 @@ The session is stored in the module's runtime. This means that it will not be available in a new Powershell session or if the module is reloaded. +### Creating a Session Using Custom Authorization Headers + +Some implementations of Jira Server (on-premise) might not be able to use the methods listed above of using HTTP Basic authentication by passing an email address and token to authenticate. In this case, you will need to create a session by passing the API Token as a bearer token in a custom Authorization header. + +To create a session using the API Token as the bearer token, you can use the New-JiraSession function: + +```powershell +$personalAccessToken = "" +$headers = @{ Authorization = "Bearer $($personalAccessToken)" } + +New-JiraSession -Headers $headers +``` + ## What About OAuth Jira does support use of OAuth, but JiraPS does not - yet. diff --git a/docs/en-US/commands/New-JiraSession.md b/docs/en-US/commands/New-JiraSession.md index 87f63a55..90792af2 100644 --- a/docs/en-US/commands/New-JiraSession.md +++ b/docs/en-US/commands/New-JiraSession.md @@ -41,6 +41,19 @@ Get-JiraIssue TEST-01 Creates a Jira session for jiraUsername. The following `Get-JiraIssue` is run using the saved session for jiraUsername. +### EXAMPLE 2 + +```powershell +$personalAccessToken = "" +$headers = @{ Authorization = "Bearer $($personalAccessToken)" } + +New-JiraSession -Headers $headers +Get-JiraIssue TEST-01 +``` + +Creates a Jira session using a Personal Access Token (PAT) as a bearer token in a custom Authorization header. +The following `Get-JiraIssue` is run using the saved session created using the PAT. + ## PARAMETERS ### -Credential @@ -52,7 +65,7 @@ Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False Position: 1 Default value: None Accept pipeline input: False