Class: Sorcery::Providers::Battlenet
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/battlenet.rb
Overview
This class adds support for OAuth with BattleNet
Instance Attribute Summary collapse
-
#auth_path ⇒ Object
Returns the value of attribute auth_path.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Instance Method Summary collapse
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Battlenet
constructor
A new instance of Battlenet.
-
#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::Oauth2
#authorize_url, #build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Battlenet
Returns a new instance of Battlenet.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sorcery/providers/battlenet.rb', line 10 def initialize super @scope = 'openid' @site = 'https://eu.battle.net/' @auth_path = '/oauth/authorize' @token_url = '/oauth/token' @user_info_path = '/oauth/userinfo' @state = SecureRandom.hex(16) end |
Instance Attribute Details
#auth_path ⇒ Object
Returns the value of attribute auth_path.
8 9 10 |
# File 'lib/sorcery/providers/battlenet.rb', line 8 def auth_path @auth_path end |
#scope ⇒ Object
Returns the value of attribute scope.
8 9 10 |
# File 'lib/sorcery/providers/battlenet.rb', line 8 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
8 9 10 |
# File 'lib/sorcery/providers/battlenet.rb', line 8 def token_url @token_url end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
8 9 10 |
# File 'lib/sorcery/providers/battlenet.rb', line 8 def user_info_path @user_info_path end |
Instance Method Details
#get_user_hash(access_token) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/sorcery/providers/battlenet.rb', line 21 def get_user_hash(access_token) response = access_token.get(user_info_path) body = JSON.parse(response.body) auth_hash(access_token).tap do |h| h[:user_info] = body h[:battletag] = body['battletag'] h[:uid] = body['id'] 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.
33 34 35 |
# File 'lib/sorcery/providers/battlenet.rb', line 33 def login_url(_params, _session) (authorize_url: auth_path) end |
#process_callback(params, _session) ⇒ Object
tries to login the user from access token
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sorcery/providers/battlenet.rb', line 38 def process_callback(params, _session) args = { code: params[:code] } get_access_token( args, token_url: token_url, client_id: @key, client_secret: @secret, grant_type: 'authorization_code', token_method: :post ) end |