AtlassianPS / JiraPS

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

Made Credential param optional to allow for bearer token authentication #439

Closed pwshmatt closed 1 year ago

pwshmatt commented 3 years ago

Description

Made the Credential parameter optional for the New-JiraSession function. If the Credential parameter is passed, add it to the parameter splat to keep existing functionality.

Motivation and Context

It appears that using Personal Access Tokens (PATs) on Jira Server on-prem is not working as described in the official module documentation. The documentation states that you should be able to pass the email address and PAT into the username and password field respectively. However, this doesn't work in all cases. Removing the mandatory attribute on the Credential parameter for the New-JiraSession function allows us to take advantage of the Header parameter that is already available without the need to pass credentials and use basic authentication. Since the Header parameter is already there and works in New-JiraSession, with this new change we can now pass in custom headers that use the more widely available Bearer token method for authentication to the Jira REST API.

Types of changes

Checklist

lipkau commented 3 years ago

Hi matt. Thanks for the PR. I don't consider using the -Headers parameter for storing the bearer token into the WebSession that obvious. I would like you to extend the JiraPS/docs/en-US/about_JiraPS_Authentication.md with a description of how how this can be used and New-JiraSession.md with an example.

pwshmatt commented 3 years ago

Hi Oliver,

Thanks for taking a look at the pull request. I've made additions to the two documents you listed. Let me know if anything looks off or needs addressed.

pwshmatt commented 3 years ago

@lipkau Just wanted to check in and see if you had a moment to review my updates to the documentation. Thanks!

pwshmatt commented 3 years ago

@lipkau Just checking in since it has been a month since your last comment and I wanted to stay on top of this to address any issues you have.

Thanks!

icsy7867 commented 11 months ago

Not sure, but i am still having trouble.

I have verified that the PAT is working with the API using postman.

However using the example code in the documentation:

$personalAccessToken = "My Token"
$headers = @{ Authorization = "Bearer $($personalAccessToken)" }
Set-JiraConfigServer -Server "https://my.datacenter.server.com"
New-JiraSession -Headers $headers 

I still get prompted for powershell get-credential, and no matter if I use my username/email addres or token for the password it still fails to authenticate.

pwshmatt commented 10 months ago

Not sure, but i am still having trouble.

I have verified that the PAT is working with the API using postman.

However using the example code in the documentation:

$personalAccessToken = "My Token"
$headers = @{ Authorization = "Bearer $($personalAccessToken)" }
Set-JiraConfigServer -Server "https://my.datacenter.server.com"
New-JiraSession -Headers $headers 

I still get prompted for powershell get-credential, and no matter if I use my username/email addres or token for the password it still fails to authenticate.

The -Credential parameter was made an optional parameter with this PR. @icsy7867 can you make sure you are running the latest version of the JiraPS module?

lipkau commented 10 months ago

try version https://www.powershellgallery.com/packages/JiraPS/2.14.7