omniauth-kongregate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ # OmniAuth::Kongregate
2
+
3
+ OmniAuth strategy for [Kongregate](http://www.kongregate.com) authentication
4
+
5
+ ## Usage
6
+
7
+ Current version is mostly focused on auto-detecting the logged-in user when the application is running on a canvas.
8
+
9
+ Just add the provider as usual, passing your app's Kongregate API key (add `/api` to the URL to get it). For example:
10
+
11
+ Rails.application.config.middleware.use OmniAuth::Builder do
12
+ provider :kongregate, 'YOUR_API_KEY'
13
+ end
14
+
15
+ When your game is first open on Kongregate, redirect to `/auth/kongregate` (preserving the `kongregate_user_id` and `kongregate_game_auth_token` parameters) to perform the authentication.
16
+
17
+ If the token is valid, `/auth/kongregate/callback` will fire. You can get the validated user_id and the username there with:
18
+
19
+ auth = request.env['omniauth.auth']
20
+ user_id = auth.uid
21
+ username = auth.extras['username']
22
+
23
+ ## TODO
24
+
25
+ - Display the Kongregate login form for non-authenticated users
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :spec
12
+
13
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1 @@
1
+ require "omniauth/strategies/kongregate"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Kongregate
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ require 'omniauth'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Kongregate
9
+ include OmniAuth::Strategy
10
+
11
+ args [:api_key]
12
+
13
+ option :fields, [:user_id, :game_auth_token]
14
+ option :uid_field, :user_id
15
+
16
+ def request_phase
17
+ redirect "/auth/kongregate/callback?user_id=#{request[:kongregate_user_id]}&game_auth_token=#{request[:kongregate_game_auth_token]}"
18
+ end
19
+
20
+ def callback_phase
21
+ @k_response = verify_kongregate_auth(request[:user_id], request[:game_auth_token])
22
+ return fail!(:invalid_credentials) unless authenticated?
23
+ super
24
+ end
25
+
26
+ uid { @k_response['user_id'] if authenticated? }
27
+
28
+ extra { { :username => @k_response['username'] } if authenticated? }
29
+
30
+ private
31
+
32
+ def authenticated?
33
+ @k_response && @k_response['success']
34
+ end
35
+
36
+ def verify_kongregate_auth(user_id, game_auth_token)
37
+ uri = URI.parse('http://www.kongregate.com/api/authenticate.json')
38
+ uri.query = URI.encode_www_form({
39
+ :user_id => user_id,
40
+ :game_auth_token => game_auth_token,
41
+ :api_key => options.api_key
42
+ })
43
+ begin
44
+ response = Net::HTTP.get_response(uri)
45
+ log :debug, "Kongregate HTTP: #{response.code} - #{response.body}"
46
+ JSON.parse(response.body)
47
+ rescue Exception => e
48
+ fail!(:kongregate_query_error, e)
49
+ nil
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-kongregate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chester / Uken Games
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 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: '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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: capybara
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
+ - !ruby/object:Gem::Dependency
79
+ name: growl
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: OmniAuth Strategy for Kongregate
127
+ email:
128
+ - chester@uken.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - lib/omniauth/strategies/kongregate.rb
134
+ - lib/omniauth-kongregate/version.rb
135
+ - lib/omniauth-kongregate.rb
136
+ - Rakefile
137
+ - README.md
138
+ homepage: ''
139
+ licenses: []
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.24
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Allows applications to get the kongregate id and username
162
+ test_files: []