omniauth-yahoo-oauth2 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 784ac84ce174a7e01cc6ff2093f87258edaffa52
4
+ data.tar.gz: 6383b98740bbac0c5b93787bb869306c828710de
5
+ SHA512:
6
+ metadata.gz: 499b6375e10ac27c860f80ae59e77b21aefb0a0958e6936355207f8d85fa79637b4ab6abe3145d5020f57b80be08213ffece4369f24e3f0647500508877d0204
7
+ data.tar.gz: 1d635f2e19db108e51d11f0303da8f0852212064aa1e3cd31a4eb1ff0f6ed589313beac37c5f69c253bafcd3b226aaf5388bab1b02ea0fe147442b1886c1c1db
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,58 @@
1
+ ## omniauth-yahoo-oauth2 ##
2
+
3
+ An unofficial, hastily-written Oauth2 OmniAuth strategy for Yahoo. Uses the authorization flow described at https://developer.yahoo.com/oauth2/guide/flows_authcode/.
4
+
5
+ Built using https://github.com/intridea/omniauth-oauth2.
6
+
7
+ ## Setup ##
8
+ `gem install omniauth-yahoo-oauth2`
9
+
10
+ Create an app at https://developer.yahoo.com/apps to get a Yahoo client ID and secret.
11
+
12
+ ## Usage ##
13
+ ```ruby
14
+ # In an initializer
15
+ Rails.application.config.middleware.use OmniAuth::Builder do
16
+ provider :yahoo_oauth2, yahoo_client_id, yahoo_secret,
17
+ name: 'yahoo'
18
+ end
19
+ ```
20
+
21
+ See https://github.com/intridea/omniauth for Omniauth instructions.
22
+
23
+ ## Notes ##
24
+ OmniAuth doesn't currently have built-in support for Basic Authentication for retrieving OAuth tokens, so `YahooOauth2#build_access_token` handles this inline.
25
+
26
+ Yahoo returns an access_token, a refresh_token, and an expiration time for the access_token. They are available in the authentication hash in the callback:
27
+
28
+ ```ruby
29
+ auth_info = request.env['omniauth.auth']
30
+ access_token = auth_info[:credentials][:token]
31
+ refresh_token = auth_info[:credentials][:refresh_token]
32
+ expires_at = auth_info[:credentials][:expires_at]
33
+ ```
34
+
35
+ You can use the refresh_token to generate new access tokens:
36
+
37
+ ```ruby
38
+ require 'oauth2'
39
+ require 'base64'
40
+
41
+ oauth_client = OAuth2::Client.new(YAHOO_CLIENT_ID, YAHOO_SECRET, {
42
+ site: 'https://api.login.yahoo.com',
43
+ authorize_url: '/oauth2/request_auth',
44
+ token_url: '/oauth2/get_token',
45
+ })
46
+
47
+ auth = "Basic #{Base64.strict_encode64("#{YAHOO_CLIENT_ID}:#{YAHOO_SECRET}")}"
48
+
49
+ new_token = oauth_client.get_token({
50
+ redirect_uri: YOUR_CALLBACK_URL,
51
+ refresh_token: YOUR_REFRESH_TOKEN,
52
+ grant_type: 'refresh_token',
53
+ headers: { 'Authorization' => auth } })
54
+ ```
55
+
56
+ ## TODO ##
57
+ - Handle failure cases. (https://developer.yahoo.com/oauth2/guide/errors/)
58
+ - Test something. Anything.
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'yahoo_oauth2')
@@ -0,0 +1,49 @@
1
+ require 'omniauth/strategies/oauth2'
2
+ require 'base64'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class YahooOauth2 < OmniAuth::Strategies::OAuth2
7
+ option :name, 'yahoo_oauth2'
8
+
9
+ option :client_options, {
10
+ site: 'https://api.login.yahoo.com',
11
+ authorize_url: '/oauth2/request_auth',
12
+ token_url: '/oauth2/get_token',
13
+ }
14
+
15
+ uid { access_token.params['xoauth_yahoo_guid'] }
16
+
17
+ info do
18
+ {
19
+ name: raw_info['profile']['nickname'],
20
+ nickname: raw_info['profile']['nickname'],
21
+ gender: raw_info['profile']['gender'],
22
+ language: raw_info['profile']['lang'],
23
+ location: raw_info['profile']['location'],
24
+ urls: {
25
+ image: raw_info['profile']['image']['imageUrl'],
26
+ profile: raw_info['profile']['profileUrl']
27
+ }
28
+ }
29
+ end
30
+
31
+ def build_access_token
32
+ verifier = request.params['code']
33
+
34
+ auth = "Basic #{Base64.strict_encode64("#{options.client_id}:#{options.client_secret}")}"
35
+
36
+ token = client.get_token(
37
+ { redirect_uri: callback_url, code: verifier, grant_type: 'authorization_code', headers: { 'Authorization' => auth } }.
38
+ merge(token_params.to_hash(symbolize_keys: true)), deep_symbolize(options.auth_token_params))
39
+
40
+ token
41
+ end
42
+
43
+ def raw_info
44
+ raw_info_url = "https://social.yahooapis.com/v1/user/#{uid}/profile?format=json"
45
+ @raw_info ||= access_token.get(raw_info_url).parsed
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'yahoo_oauth2')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module YahooOauth2
3
+ VERSION = '1.1.0'
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.join('..', 'lib', 'omniauth', 'yahoo_oauth2', 'version'), __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.add_runtime_dependency 'omniauth', '~> 1.1'
5
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
6
+ gem.add_development_dependency 'bundler', '~> 1.0'
7
+
8
+ gem.authors = ['Amir Manji']
9
+ gem.email = ['amanji75@gmail.com']
10
+ gem.description = 'A Yahoo OAuth2 strategy for OmniAuth.'
11
+ gem.summary = gem.description
12
+ gem.homepage = 'https://github.com/amirmanji/omniauth-yahoo-oauth2'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.name = 'omniauth-yahoo-oauth2'
17
+ gem.require_paths = ['lib']
18
+ gem.version = OmniAuth::YahooOauth2::VERSION
19
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-yahoo-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Amir Manji
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: A Yahoo OAuth2 strategy for OmniAuth.
56
+ email:
57
+ - amanji75@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - lib/omniauth-yahoo-oauth2.rb
66
+ - lib/omniauth/strategies/yahoo_oauth2.rb
67
+ - lib/omniauth/yahoo_oauth2.rb
68
+ - lib/omniauth/yahoo_oauth2/version.rb
69
+ - omniauth-yahoo-oauth2.gemspec
70
+ homepage: https://github.com/amirmanji/omniauth-yahoo-oauth2
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: A Yahoo OAuth2 strategy for OmniAuth.
94
+ test_files: []