omniauth-bnet 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ stunnel*
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-bnet.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-bnet (0.0.1)
5
+ omniauth (~> 1.0)
6
+ omniauth-oauth2 (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ faraday (0.9.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ hashie (3.2.0)
14
+ jwt (1.0.0)
15
+ multi_json (1.10.1)
16
+ multi_xml (0.5.5)
17
+ multipart-post (2.0.0)
18
+ oauth2 (1.0.0)
19
+ faraday (>= 0.8, < 0.10)
20
+ jwt (~> 1.0)
21
+ multi_json (~> 1.3)
22
+ multi_xml (~> 0.5)
23
+ rack (~> 1.2)
24
+ omniauth (1.2.2)
25
+ hashie (>= 1.2, < 4)
26
+ rack (~> 1.0)
27
+ omniauth-oauth2 (1.2.0)
28
+ faraday (>= 0.8, < 0.10)
29
+ multi_json (~> 1.3)
30
+ oauth2 (~> 1.0)
31
+ omniauth (~> 1.2)
32
+ rack (1.5.2)
33
+ rake (0.9.6)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.6)
40
+ omniauth-bnet!
41
+ rake (~> 0)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Christopher Giroir
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # OmniAuth Bnet
2
+
3
+ This is an OmniAuth strategy for authenticating to Blizzard's Battle.net OAuth
4
+ service. In order to use it you need to register an application at the
5
+ [Battle.net Developer Portal](https://dev.battle.net)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'omniauth-bnet'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-bnet
20
+
21
+ ## Usage
22
+
23
+ use OmniAuth::Builder do
24
+ provider :bnet, ENV['BNET_KEY'], ENV['BNET_SECRET']
25
+ end
26
+
27
+ ### Scopes
28
+
29
+ In order to provide a list of scopes to request from battle.net:
30
+
31
+ use OmniAuth::Builder do
32
+ provider :bnet, ENV['BNET_KEY'], ENV['BNET_SECRET'], scope: "wow.profile,sc2.profile"
33
+ end
34
+
35
+ ## License
36
+
37
+ [The MIT License](http://opensource.org/licenses/MIT)
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-github'
5
+ gem 'omniauth-bnet'
6
+ gem 'httplog'
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ faraday (0.9.0)
5
+ multipart-post (>= 1.2, < 3)
6
+ hashie (3.2.0)
7
+ httplog (0.2.7)
8
+ jwt (1.0.0)
9
+ multi_json (1.10.1)
10
+ multi_xml (0.5.5)
11
+ multipart-post (2.0.0)
12
+ oauth2 (1.0.0)
13
+ faraday (>= 0.8, < 0.10)
14
+ jwt (~> 1.0)
15
+ multi_json (~> 1.3)
16
+ multi_xml (~> 0.5)
17
+ rack (~> 1.2)
18
+ omniauth (1.2.2)
19
+ hashie (>= 1.2, < 4)
20
+ rack (~> 1.0)
21
+ omniauth-bnet (1.0.0)
22
+ omniauth (~> 1.0)
23
+ omniauth-oauth2 (~> 1.1)
24
+ omniauth-github (1.1.2)
25
+ omniauth (~> 1.0)
26
+ omniauth-oauth2 (~> 1.1)
27
+ omniauth-oauth2 (1.2.0)
28
+ faraday (>= 0.8, < 0.10)
29
+ multi_json (~> 1.3)
30
+ oauth2 (~> 1.0)
31
+ omniauth (~> 1.2)
32
+ rack (1.5.2)
33
+ rack-protection (1.5.3)
34
+ rack
35
+ sinatra (1.4.5)
36
+ rack (~> 1.4)
37
+ rack-protection (~> 1.4)
38
+ tilt (~> 1.3, >= 1.3.4)
39
+ tilt (1.4.1)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ httplog
46
+ omniauth-bnet
47
+ omniauth-github
48
+ sinatra
@@ -0,0 +1,89 @@
1
+ # This example provides login links for github and bnet in order to test that
2
+ # bnet oauth is correctly working.
3
+
4
+ require 'omniauth'
5
+ require 'omniauth-bnet'
6
+ require 'omniauth-github'
7
+ require 'sinatra'
8
+
9
+ # Uncomment to see requests going back and forth <3
10
+ # require 'httplog'
11
+ # HttpLog.options[:log_headers] = true
12
+
13
+ configure do
14
+ use OmniAuth::Builder do
15
+ provider :github, ENV['GITHUB_ID'], ENV['GITHUB_SECRET']
16
+ provider :bnet, ENV['BNET_ID'], ENV['BNET_SECRET'], scope: "wow.profile sc2.profile"
17
+ end
18
+
19
+ OmniAuth.config.full_host = "https://local.test.battle.net"
20
+
21
+ enable :sessions
22
+ enable :inline_templates
23
+ end
24
+
25
+ helpers do
26
+ def current_user
27
+ session[:user_id]
28
+ end
29
+
30
+ def current_user_info
31
+ session[:user_info]
32
+ end
33
+
34
+ def h(text)
35
+ Rack::Utils.escape_html(text)
36
+ end
37
+ end
38
+
39
+ get '/' do
40
+ if current_user
41
+ erb '<h1>Sinatra OAuth Test</h1><%=current_user%><br><pre><%=h current_user_info%></pre><br><a href="/logout">Logout</a>'
42
+ else
43
+ erb '<h1>Sinatra OAuth Test</h1><a href="/auth/github">Login with Github</a><br><a href="/auth/bnet">Login with Bnet</a>'
44
+ end
45
+ end
46
+
47
+ get '/auth/:name/callback' do
48
+ auth = request.env["omniauth.auth"]
49
+ session[:user_id] = auth["uid"]
50
+ session[:user_info] = auth["info"]
51
+ redirect OmniAuth.config.full_host
52
+ end
53
+
54
+ get '/auth/failure' do
55
+ erb "<h1>Authentication Failed:</h1><h3>message:#{params[:message]}<h3> <pre>#{params}</pre>"
56
+ end
57
+
58
+ get '/auth/:provider/deauthorized' do
59
+ erb "#{params[:provider]} has deauthorized this app."
60
+ end
61
+
62
+ get '/logout' do
63
+ session[:user_id] = nil
64
+ session[:user_info] = nil
65
+ redirect OmniAuth.config.full_host
66
+ end
67
+
68
+ __END__
69
+
70
+ @@ layout
71
+ <html>
72
+ <head>
73
+ <!-- Latest compiled and minified CSS -->
74
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
75
+
76
+ <!-- Optional theme -->
77
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
78
+
79
+ <!-- Latest compiled and minified JavaScript -->
80
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
81
+ </head>
82
+ <body>
83
+ <div class='container'>
84
+ <div class='content'>
85
+ <%= yield %>
86
+ </div>
87
+ </div>
88
+ </body>
89
+ </html>
@@ -0,0 +1,2 @@
1
+ require "omniauth-bnet/version"
2
+ require "omniauth/strategies/bnet"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Bnet
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,83 @@
1
+ require 'omniauth-oauth2'
2
+ require 'base64'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Bnet < OmniAuth::Strategies::OAuth2
7
+ option :region, :us
8
+ option :client_options, {
9
+ :scope => 'wow.profile sc2.profile'
10
+ }
11
+
12
+ def client
13
+ # Setup urls based on region option
14
+ if !options.client_options.has_key(:authorize_url)
15
+ options.client_options[:authorize_url] = "https://#{getHost(options.region)}/oauth/authorize"
16
+ end
17
+ if !options.client_options.has_key(:token_url)
18
+ options.client_options[:token_url] = "https://#{getHost(options.region)}/oauth/token"
19
+ end
20
+ if !options.client_options.has_key(:site)
21
+ options.client_options[:site] = "https://#{getMasheryHost(options.region)}/"
22
+ end
23
+
24
+ super
25
+ end
26
+
27
+ def request_phase
28
+ super
29
+ end
30
+
31
+ def authorize_params
32
+ super.tap do |params|
33
+ %w[scope client_options].each do |v|
34
+ if request.params[v]
35
+ params[v.to_sym] = request.params[v]
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ uid { raw_info['id'].to_s }
42
+
43
+ info do
44
+ { :id => raw_info["id"],
45
+ :battletag => raw_info["battletag"] }
46
+ end
47
+
48
+ def raw_info
49
+ return @raw_info if @raw_info
50
+
51
+ access_token.options[:mode] = :query
52
+
53
+ id = access_token.get('account/user/id').parsed['id']
54
+ battletag = access_token.get('account/user/battletag').parsed['battletag']
55
+
56
+ @raw_info = {
57
+ 'id' => id,
58
+ 'battletag' => battletag
59
+ }
60
+ end
61
+
62
+ private
63
+
64
+ def getHost(region)
65
+ case region
66
+ when "cn"
67
+ "www.battlenet.com.cn"
68
+ else
69
+ "#{region}.battle.net"
70
+ end
71
+ end
72
+
73
+ def getMasheryHost(region)
74
+ case region
75
+ when "cn"
76
+ "api.battlenet.com.cn"
77
+ else
78
+ "#{region}.api.battle.net"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-bnet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-bnet"
8
+ spec.version = OmniAuth::Bnet::VERSION
9
+ spec.authors = ["Christopher Giroir"]
10
+ spec.email = ["cgiroir@blizzard.com"]
11
+ spec.summary = %q{Omniauth Strategy for Battle.net}
12
+ spec.description = %q{Omniauth Strategy for Battle.net OAuth Login. For more info visit https://dev.battle.net}
13
+ spec.homepage = "https://github.com/Blizzard/omniauth-bnet"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'omniauth', '~> 1.0'
22
+ spec.add_dependency 'omniauth-oauth2', '~> 1.1'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", "~> 0"
26
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bnet
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Giroir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-oauth2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Omniauth Strategy for Battle.net OAuth Login. For more info visit https://dev.battle.net
79
+ email:
80
+ - cgiroir@blizzard.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - examples/Gemfile
92
+ - examples/Gemfile.lock
93
+ - examples/sinatra.rb
94
+ - lib/omniauth-bnet.rb
95
+ - lib/omniauth-bnet/version.rb
96
+ - lib/omniauth/strategies/bnet.rb
97
+ - omniauth-bnet.gemspec
98
+ homepage: https://github.com/Blizzard/omniauth-bnet
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Omniauth Strategy for Battle.net
123
+ test_files: []