Class: Sorcery::Providers::Jira
- Includes:
- Sorcery::Protocols::Oauth
- Defined in:
- lib/sorcery/providers/jira.rb
Overview
This class adds support for OAuth with Jira
config.jira.key = <key>
config.jira.secret = <secret>
...
Instance Attribute Summary collapse
-
#access_token_path ⇒ Object
Returns the value of attribute access_token_path.
-
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#private_key_file ⇒ Object
Returns the value of attribute private_key_file.
-
#request_token_path ⇒ Object
Returns the value of attribute request_token_path.
-
#signature_method ⇒ Object
Returns the value of attribute signature_method.
-
#site ⇒ Object
Returns the value of attribute site.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #key, #original_callback_url, #secret, #state, #user_info_mapping
Instance Method Summary collapse
-
#get_consumer ⇒ Object
Override included get_consumer method to provide authorize_path read extra configurations.
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Jira
constructor
A new instance of Jira.
-
#login_url(_params, session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
-
#process_callback(params, session) ⇒ Object
tries to login the user from access token.
Methods included from Sorcery::Protocols::Oauth
#authorize_url, #get_access_token, #get_request_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Jira
Returns a new instance of Jira.
15 16 17 18 19 20 21 22 |
# File 'lib/sorcery/providers/jira.rb', line 15 def initialize @configuration = { authorize_path: '/authorize', request_token_path: '/request-token', access_token_path: '/access-token' } @user_info_path = '/users/me' end |
Instance Attribute Details
#access_token_path ⇒ Object
Returns the value of attribute access_token_path.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def access_token_path @access_token_path end |
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def @authorize_path end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def callback_url @callback_url end |
#private_key_file ⇒ Object
Returns the value of attribute private_key_file.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def private_key_file @private_key_file end |
#request_token_path ⇒ Object
Returns the value of attribute request_token_path.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def request_token_path @request_token_path end |
#signature_method ⇒ Object
Returns the value of attribute signature_method.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def signature_method @signature_method end |
#site ⇒ Object
Returns the value of attribute site.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def site @site end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
12 13 14 |
# File 'lib/sorcery/providers/jira.rb', line 12 def user_info_path @user_info_path end |
Instance Method Details
#get_consumer ⇒ Object
Override included get_consumer method to provide authorize_path read extra configurations
26 27 28 29 30 31 32 |
# File 'lib/sorcery/providers/jira.rb', line 26 def get_consumer @configuration = @configuration.merge(site: site, signature_method: signature_method, consumer_key: key, private_key_file: private_key_file) ::OAuth::Consumer.new(@key, @secret, @configuration) end |
#get_user_hash(access_token) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/sorcery/providers/jira.rb', line 34 def get_user_hash(access_token) response = access_token.get(user_info_path) auth_hash(access_token).tap do |h| h[:user_info] = JSON.parse(response.body)['users'].first h[:uid] = user_hash[:user_info]['id'].to_s end end |
#login_url(_params, session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sorcery/providers/jira.rb', line 45 def login_url(_params, session) req_token = get_request_token session[:request_token] = req_token.token session[:request_token_secret] = req_token.secret # it was like that -> redirect_to authorize_url({ request_token: req_token.token, request_token_secret: req_token.secret }) # for some reason Jira does not need these parameters get_request_token( session[:request_token], session[:request_token_secret] ). end |
#process_callback(params, session) ⇒ Object
tries to login the user from access token
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sorcery/providers/jira.rb', line 60 def process_callback(params, session) args = { oauth_verifier: params[:oauth_verifier], request_token: session[:request_token], request_token_secret: session[:request_token_secret] } args[:code] = params[:code] if params[:code] get_access_token(args) end |