Class: OmniAuth::Strategies::Qiita
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Qiita
- Defined in:
- lib/omniauth/strategies/qiita.rb
Constant Summary collapse
- DEFAULT_SCOPE =
'read_qiita'
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #build_access_token ⇒ Object
- #build_params_for_access_token ⇒ Object
- #build_request_option_for_access_token ⇒ Object
- #handle_access_token_response(response) ⇒ Object
- #raw_info ⇒ Object
- #request_access_token ⇒ Object
- #set_scope(params) ⇒ Object
- #urls(raw_info) ⇒ Object
Instance Method Details
#authorize_params ⇒ Object
62 63 64 65 66 |
# File 'lib/omniauth/strategies/qiita.rb', line 62 def super.tap do |params| set_scope params end end |
#build_access_token ⇒ Object
99 100 101 |
# File 'lib/omniauth/strategies/qiita.rb', line 99 def build_access_token handle_access_token_response(request_access_token) end |
#build_params_for_access_token ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/omniauth/strategies/qiita.rb', line 72 def build_params_for_access_token { code: request.params['code'], client_id: .client_id, client_secret: .client_secret } end |
#build_request_option_for_access_token ⇒ Object
80 81 82 83 84 85 |
# File 'lib/omniauth/strategies/qiita.rb', line 80 def build_request_option_for_access_token { headers: { 'Content-Type' => 'application/json' }, body: MultiJson.dump(build_params_for_access_token), }.merge(['token_params']) end |
#handle_access_token_response(response) ⇒ Object
93 94 95 96 97 |
# File 'lib/omniauth/strategies/qiita.rb', line 93 def handle_access_token_response response error = Error.new(response) fail(error) if client.[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token']) ::OAuth2::AccessToken.from_hash(client, response.parsed.merge(deep_symbolize(.auth_token_params))) end |
#raw_info ⇒ Object
40 41 42 |
# File 'lib/omniauth/strategies/qiita.rb', line 40 def raw_info @raw_info ||= access_token.get('/api/v2/authenticated_user').parsed || {} end |
#request_access_token ⇒ Object
87 88 89 90 91 |
# File 'lib/omniauth/strategies/qiita.rb', line 87 def request_access_token client.request(:post, client.token_url, build_request_option_for_access_token).tap do |res| res.parsed['access_token'] = res.parsed.delete('token') end end |
#set_scope(params) ⇒ Object
68 69 70 |
# File 'lib/omniauth/strategies/qiita.rb', line 68 def set_scope params params[:scope] ||= request.params['scope'] || DEFAULT_SCOPE end |
#urls(raw_info) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/omniauth/strategies/qiita.rb', line 44 def urls(raw_info) hash = {} [ ['Facebook', 'facebook_id', ->(id){"https://www.facebook.com/#{id}"}], ['Github', 'github_login_name', ->(id){"https://github.com/#{id}"}], ['LinkedIn', 'linkedin_id', ->(id){"https://www.linkedin.com/in/#{id}"}], ['Twitter', 'twitter_screen_name', ->(id){"https://twitter.com/#{id}"}], ['Website', 'website_url', ->(url){url}] ].each do |label, key, url_gen| if raw_info.key? key and raw_info[key] and raw_info[key].length > 0 hash[label] = url_gen.call(raw_info[key]) end end hash end |