Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get client by access_token #329

Open
puneet18190 opened this issue Apr 7, 2019 · 7 comments
Open

How to get client by access_token #329

puneet18190 opened this issue Apr 7, 2019 · 7 comments

Comments

@puneet18190
Copy link

I implemented OAuth 2.0 and able to get jira access_token and then able to use all jira apis.
Ref: https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/

I need to know how can I JIRA Client by access_token so that I can use all methods of jira-ruby gem.

`
options = {
....}

client = JIRA::Client.new(options)
`

Under options, what should I pass to get client.
I have created app under JIRA apps and I have client_id, secret token and access_token.

@eddygarcas
Copy link

eddygarcas commented Apr 18, 2019

Hi
I'm using these options to get into jira using OAuth,

options = {
	site: setting.site,
	rest_base_path: setting.base_path,
	context_path: setting.context,
	auth_type:  :oauth,
	http_debug: setting.debug?,
	signature_method: setting.signature_method,
	request_token_path: "/plugins/servlet/oauth/request-token",
	authorize_path: "/plugins/servlet/oauth/authorize",
	access_token_path: "/plugins/servlet/oauth/access-token",
	private_key_file: File.create_rsa_file(setting.key_data, setting.key_file),
	consumer_key: setting.consumer_key
}

setting it's just an internal object that i'm using to store user JIRA settings, the important thing here are the keys.
Hopefully helps

@JeffKandel
Copy link

I am encountering the same issue. My application relies on omniauth and omniauth-atlassian-oauth2 to retrieve an access token. These gems utilize OAuth 2.0 (3LO) (also known as "three-legged OAuth" or "authorization code grants"), as descripted in the initial comment above.

Is there anyway to instantiate the JIRA::Client with just the access token and domain?

@JeffKandel
Copy link

Found an answer in the comments of this PR: #346

client = JIRA::Client.new(
      username: nil,
      password: nil,
      auth_type: :basic,
      site: 'https://api.atlassian.com',
      context_path: "/ex/jira/#{cloudid}",
      default_headers: { 'Authorization' => "Bearer #{token}" }
    )

I still needed to set username and password to nil to get this to work.

@xmarlox
Copy link

xmarlox commented Jul 22, 2020

@JeffKandel
any unexpected behavior you're experiencing while using OAuth 2.0 to retrieve JIRA::Resource::Issue together with or expanding the changelog? 🤔

@JeffKandel
Copy link

We ended up using a different approach so I'm not sure. Best of luck!

@xmarlox
Copy link

xmarlox commented Jul 22, 2020

@JeffKandel
I see. It's very strange behavior on my side. most of the time I encountered the following errors:

#<JIRA::HTTPError: Not Found - Issue does not exist or you do not have permission to see it.>
#<JIRA::HTTPError: Not Found - No project could be found with key 'PJ'.>
#<JIRA::HTTPError: Bad Request - 400 Request Header Or Cookie Too Large 400 Bad Request Request Header Or Cookie Too Large>

sometimes #<JIRA::HTTPError: Unauthenticated>

@freebian
Copy link

Did anybody solve this?
I try to authenticate as @JeffKandel described, but I get an empty array back when I try to access all projects via:

@client.Project.all

I verified my access token using Postman. It worked fine. Also very strange: If I mess with the token in Postman (e.g. putting in something random) I also get an empty array back.

So, my assumption here is, that the header is not set properly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants