3

I'm trying to hook up an OAuth consumer using 2-legged authentication. I have two questions:

1) is it possible to use Oauth with a custom REST plugin (as opposed to the built-in API)

2) as a test of the built-in REST API, I'm trying the following, and receiving:

<Net::HTTPUnauthorized 401 Unauthorized readbody=true>
{"errorMessages":["You do not have the permission to see the specified issue","Login Required"],"errors":{}}

Here is the test method:

jira_url = "http://localhost:2990/jira"

consumer_key = "hardcoded-consumer"
consumer_secret = OpenSSL::PKey::RSA.new(IO.read(File.dirname(__FILE__) + "/../rsakey.pem"))

@consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, {
    :site => 'http://localhost:2990',
    :context_path       => '/jira',
    :signature_method   => 'RSA-SHA1',
    :auth_type          => :oauth,
    :scheme => :header,
    :oauth_callback => false,
    :ssl_verify_mode    => OpenSSL::SSL::VERIFY_PEER,
    :use_ssl            => true,
    :http_method => :post,
    :request_token_path => jira_url + '/plugins/servlet/oauth/request-token',
    :access_token_path  => jira_url + '/plugins/servlet/oauth/access-token',
    :authorize_path     => jira_url + '/plugins/servlet/oauth/authorize'
})

testurl = jira_url + "/rest/api/latest/issue/SPI-1"

puts "1 #################################### first method"
req = @consumer.create_signed_request(:get, testurl, nil)
res = Net::HTTP.start('localhost', '2990') { |http| http.request(req) }
puts res.inspect
puts res.body

puts "2 #################################### second method"
@acc_tok = OAuth::AccessToken.new @consumer
resp = @acc_tok.get(testurl)
puts @acc_tok.inspect
puts resp.inspect
puts resp.body

Both methods output the same error.

Can anyone tell me what I'm doing wrong?

jbeck
  • 1,964
  • 1
  • 18
  • 21

1 Answers1

0

Answer 1. OAuth is an authorization framework and REST is a stateless, client-server, cacheable communications protocol. So yes you can use OAuth for authentication with your custom REST plugin.

Answer 2. You could try without SSL or use :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE if it works, than problem is in your SSL connection. Alternatively you may try basic authentication:

{
     :username => "*Your JIRA username*",
     :password => "*Your JIRA password*",
     :site     => 'http://localhost:2990/',
     :context_path => 'jira',
     :auth_type => :basic,
     :use_ssl => true,
     :signature_method   => 'RSA-SHA1',
     :ssl_verify_mode    => OpenSSL::SSL::VERIFY_NONE
}

I found this gem very useful.

Community
  • 1
  • 1
Amit Singh
  • 118
  • 12