AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
321 stars 131 forks source link

New-JiraSession not working with PAT - UPDATE DOCUMENTATION #448

Open childsc opened 2 years ago

childsc commented 2 years ago

Description

We will be looking to disable the basic Authentication against Jira in the next few months. However we are not able to create new sessions when using the PAT. According to the documentation we are supposed to use the user's email address and the PAT to create a session. However, this does not appear to be working. https://atlassianps.org/docs/JiraPS/about/authentication.html#api-token

Steps To Reproduce

  1. Go to profile and create a new PAT
  2. Perform the following script:
  3. $password = ConvertTo-SecureString '<TOKEN>' -AsPlainText -Force $creds = New-Object System.Management.Automation.PSCredential ('users@emailAddress.com', $password) New-JiraSession -Credential $creds

Expected behavior

Expected to see the following (as we see with basic Auth):

Username WebSession


test Microsoft.PowerShell.Commands.WebRequestSession

Your Environment

Get-Module JiraPS -ListAvailable | Select Name, Version

Name   Version
----   -------
JiraPS 2.14.6

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Alreanaes commented 2 years ago

tldr; try New-JiraSession -Headers @{Authorization="Bearer <PAT Token>"} -Credential $([System.Management.Automation.PSCredential]::Empty)

I was having a similar issue authenticating to a Jira Server instance. All the documentation is for Jira Cloud. I was able to find an explanation of the difference when using a PAT here and I confirmed with curl. So, I took a dive into New-JiraSession and then Invoke-JiraMethod. Apparently you can use empty credentials $creds = [System.Management.Automation.PSCredential]::Empty and manually create the authorization header. New-JiraSession -Headers @{Authorization="Bearer <PAT Token>"} -Credential $creds

childsc commented 2 years ago

This should actually by Please update the Documentation around PAT. Many thanks @Alreanaes

ybeltrikov commented 6 months ago

Using JiraPS 2.14.6 trying to connect to Jira Server and on New-JiraSession -Headers @{Authorization="Bearer <PAT Token>"} -Credential $([System.Management.Automation.PSCredential]::Empty

I get an error: Invoke-JiraMethod : token contains an invalid number of segments