Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically get access_token from OAuth - Using JIRA-Ruby gem
    text
    copied!<p>I'm trying to write a JIRA-ruby script (only be used from command-line) to mark some JIRA issue closed automatically.</p> <p>I borrow an example from <a href="https://github.com/trineo/jira-ruby/blob/master/example.rb" rel="nofollow">here</a> because I'm using 'jira-ruby' gem.</p> <p>This works however it will pop-up a browser asking you to click "Allow" to get the access_token. I would like to do this programmatically, but I don't think the API was built for this purpose. As access_token changes every time, and this script will run periodically in a cronjob, so we need to have a way to do this. Any idea what other ways we can do this?</p> <pre><code>require 'jira' @jira = JIRA::Client.new({:site =&gt; 'http://localhost:2990', :context_path =&gt; '/jira', :consumer_key =&gt; 'test-jira', :private_key_file =&gt; "rsakey.pem"}) if ARGV.length == 0 # If not passed any command line arguments, open a browser and prompt the # user for the OAuth verifier. request_token = @jira.request_token puts "Opening #{request_token.authorize_url}" system "open #{request_token.authorize_url}" puts "Enter the oauth_verifier: " oauth_verifier = gets.strip access_token = @jira.init_access_token(:oauth_verifier =&gt; oauth_verifier) puts "Access token: #{access_token.token} secret: #{access_token.secret}" elsif ARGV.length == 2 # Otherwise assume the arguments are a previous access token and secret. access_token = @jira.set_access_token(ARGV[0], ARGV[1]) else # Script must be passed 0 or 2 arguments raise "Usage: #{$0} [ token secret ]" end # Show all projects projects = @jira.Project.all projects.each do |project| puts "Project -&gt; key: #{project.key}, name: #{project.name}" end issue = @jira.Issue.find('DEMO-1') puts issue </code></pre> <p>I know there's a way to use long-life access tokens, but not really use if Jira supports it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload