identity_client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/identity_client/sessions_controller.rb +11 -2
- data/app/models/identity_client/access_grant.rb +26 -0
- data/app/models/identity_client/user.rb +2 -0
- data/db/migrate/20130410122748_create_identity_client_access_grants.rb +11 -0
- data/lib/identity_client/version.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +32 -0
- data/test/dummy/log/development.log +16 -0
- data/test/dummy/log/test.log +9 -0
- data/test/fixtures/identity_client/access_grants.yml +11 -0
- data/test/unit/identity_client/access_grant_test.rb +9 -0
- metadata +10 -2
@@ -1,11 +1,20 @@
|
|
1
1
|
module IdentityClient
|
2
2
|
class SessionsController < ApplicationController
|
3
3
|
def create
|
4
|
-
auth
|
5
|
-
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"].to_s) || User.create_with_omniauth(auth)
|
4
|
+
AccessGrant.create_or_update_by_user_and_credentials(user, auth['credentials'])
|
6
5
|
|
7
6
|
session[:user_id] = user.id
|
8
7
|
redirect_to '/'
|
9
8
|
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def user
|
13
|
+
@user ||= User.find_by_provider_and_uid(auth['provider'], auth['uid'].to_s) || User.create_with_omniauth(auth)
|
14
|
+
end
|
15
|
+
|
16
|
+
def auth
|
17
|
+
@auth ||= request.env['omniauth.auth']
|
18
|
+
end
|
10
19
|
end
|
11
20
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module IdentityClient
|
2
|
+
class AccessGrant < ActiveRecord::Base
|
3
|
+
attr_accessible :access_token, :expires_at, :user_id
|
4
|
+
|
5
|
+
belongs_to :user
|
6
|
+
|
7
|
+
def self.create_or_update_by_user_and_credentials(user, credentials)
|
8
|
+
attributes = {
|
9
|
+
access_token: credentials['token'],
|
10
|
+
expires_at: Time.at(credentials['expires_at'])
|
11
|
+
}
|
12
|
+
|
13
|
+
if (grant = AccessGrant.by_user(user))
|
14
|
+
grant.update_attributes(attributes)
|
15
|
+
else
|
16
|
+
grant = user.create_access_grant(attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
grant
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.by_user(user)
|
23
|
+
AccessGrant.where(user_id: user.id).first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20130410122748) do
|
15
|
+
|
16
|
+
create_table "identity_client_access_grants", :force => true do |t|
|
17
|
+
t.integer "user_id"
|
18
|
+
t.string "access_token"
|
19
|
+
t.datetime "expires_at"
|
20
|
+
t.datetime "created_at", :null => false
|
21
|
+
t.datetime "updated_at", :null => false
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table "identity_client_users", :force => true do |t|
|
25
|
+
t.string "provider"
|
26
|
+
t.string "uid"
|
27
|
+
t.string "name"
|
28
|
+
t.datetime "created_at", :null => false
|
29
|
+
t.datetime "updated_at", :null => false
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -902,3 +902,19 @@ Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
|
|
902
902
|
|
903
903
|
|
904
904
|
Started GET "/identity_client/auth/icis" for 127.0.0.1 at 2013-04-06 09:47:28 -0400
|
905
|
+
Connecting to database specified by database.yml
|
906
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
907
|
+
[1m[35m (1.2ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
908
|
+
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
909
|
+
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
910
|
+
Migrating to CreateIdentityClientUsers (20130406131436)
|
911
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
912
|
+
[1m[35m (0.4ms)[0m CREATE TABLE "identity_client_users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "provider" varchar(255), "uid" varchar(255), "name" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
913
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20130406131436')[0m
|
914
|
+
[1m[35m (1.2ms)[0m commit transaction
|
915
|
+
Migrating to CreateIdentityClientAccessGrants (20130410122748)
|
916
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
917
|
+
[1m[35m (0.4ms)[0m CREATE TABLE "identity_client_access_grants" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "access_token" varchar(255), "expires_at" datetime, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
918
|
+
[1m[36m (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20130410122748')[0m
|
919
|
+
[1m[35m (0.9ms)[0m commit transaction
|
920
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
data/test/dummy/log/test.log
CHANGED
@@ -1,3 +1,12 @@
|
|
1
1
|
Connecting to database specified by database.yml
|
2
2
|
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
3
3
|
[1m[35m (0.0ms)[0m rollback transaction
|
4
|
+
Connecting to database specified by database.yml
|
5
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
6
|
+
Processing by HomeController#show as HTML
|
7
|
+
Redirected to http://test.host/identity_client/auth/icis
|
8
|
+
Filter chain halted as :authenticate rendered or redirected
|
9
|
+
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
|
10
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
11
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
12
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: identity_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -87,10 +87,12 @@ files:
|
|
87
87
|
- app/controllers/identity_client/application_controller.rb
|
88
88
|
- app/controllers/identity_client/sessions_controller.rb
|
89
89
|
- app/helpers/identity_client/application_helper.rb
|
90
|
+
- app/models/identity_client/access_grant.rb
|
90
91
|
- app/models/identity_client/user.rb
|
91
92
|
- app/views/layouts/identity_client/application.html.erb
|
92
93
|
- config/routes.rb
|
93
94
|
- db/migrate/20130406131436_create_identity_client_users.rb
|
95
|
+
- db/migrate/20130410122748_create_identity_client_access_grants.rb
|
94
96
|
- lib/identity_client/engine.rb
|
95
97
|
- lib/identity_client/version.rb
|
96
98
|
- lib/identity_client.rb
|
@@ -125,6 +127,7 @@ files:
|
|
125
127
|
- test/dummy/config/routes.rb
|
126
128
|
- test/dummy/config.ru
|
127
129
|
- test/dummy/db/development.sqlite3
|
130
|
+
- test/dummy/db/schema.rb
|
128
131
|
- test/dummy/db/test.sqlite3
|
129
132
|
- test/dummy/log/development.log
|
130
133
|
- test/dummy/log/test.log
|
@@ -151,10 +154,12 @@ files:
|
|
151
154
|
- test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
152
155
|
- test/dummy/tmp/cache/assets/DED/F20/sprockets%2Fe2ec6b180edb4e4d0c5e691da72ad13a
|
153
156
|
- test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
157
|
+
- test/fixtures/identity_client/access_grants.yml
|
154
158
|
- test/fixtures/identity_client/users.yml
|
155
159
|
- test/identity_client_test.rb
|
156
160
|
- test/integration/navigation_test.rb
|
157
161
|
- test/test_helper.rb
|
162
|
+
- test/unit/identity_client/access_grant_test.rb
|
158
163
|
- test/unit/identity_client/user_test.rb
|
159
164
|
homepage: http://iorahealth.com
|
160
165
|
licenses: []
|
@@ -208,6 +213,7 @@ test_files:
|
|
208
213
|
- test/dummy/config/routes.rb
|
209
214
|
- test/dummy/config.ru
|
210
215
|
- test/dummy/db/development.sqlite3
|
216
|
+
- test/dummy/db/schema.rb
|
211
217
|
- test/dummy/db/test.sqlite3
|
212
218
|
- test/dummy/log/development.log
|
213
219
|
- test/dummy/log/test.log
|
@@ -234,8 +240,10 @@ test_files:
|
|
234
240
|
- test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
|
235
241
|
- test/dummy/tmp/cache/assets/DED/F20/sprockets%2Fe2ec6b180edb4e4d0c5e691da72ad13a
|
236
242
|
- test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
|
243
|
+
- test/fixtures/identity_client/access_grants.yml
|
237
244
|
- test/fixtures/identity_client/users.yml
|
238
245
|
- test/identity_client_test.rb
|
239
246
|
- test/integration/navigation_test.rb
|
240
247
|
- test/test_helper.rb
|
248
|
+
- test/unit/identity_client/access_grant_test.rb
|
241
249
|
- test/unit/identity_client/user_test.rb
|