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.
@@ -1,11 +1,20 @@
1
1
  module IdentityClient
2
2
  class SessionsController < ApplicationController
3
3
  def create
4
- auth = request.env["omniauth.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
@@ -1,5 +1,7 @@
1
1
  module IdentityClient
2
2
  class User < ActiveRecord::Base
3
+ has_one :access_grant
4
+
3
5
  def self.create_with_omniauth(auth)
4
6
  create! do |user|
5
7
  user.provider = auth["provider"]
@@ -0,0 +1,11 @@
1
+ class CreateIdentityClientAccessGrants < ActiveRecord::Migration
2
+ def change
3
+ create_table :identity_client_access_grants do |t|
4
+ t.integer :user_id
5
+ t.string :access_token
6
+ t.datetime :expires_at
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module IdentityClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
+  (0.1ms) select sqlite_version(*)
907
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
908
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
909
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
910
+ Migrating to CreateIdentityClientUsers (20130406131436)
911
+  (0.0ms) begin transaction
912
+  (0.4ms) 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
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20130406131436')
914
+  (1.2ms) commit transaction
915
+ Migrating to CreateIdentityClientAccessGrants (20130410122748)
916
+  (0.0ms) begin transaction
917
+  (0.4ms) 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
+  (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES ('20130410122748')
919
+  (0.9ms) commit transaction
920
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
@@ -1,3 +1,12 @@
1
1
  Connecting to database specified by database.yml
2
2
   (0.3ms) begin transaction
3
3
   (0.0ms) rollback transaction
4
+ Connecting to database specified by database.yml
5
+  (0.3ms) begin transaction
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
+  (0.1ms) rollback transaction
11
+  (0.1ms) begin transaction
12
+  (0.0ms) rollback transaction
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ user_id: 1
5
+ access_token: MyString
6
+ expires_at: 2013-04-10 08:27:48
7
+
8
+ two:
9
+ user_id: 1
10
+ access_token: MyString
11
+ expires_at: 2013-04-10 08:27:48
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module IdentityClient
4
+ class AccessGrantTest < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
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.2
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-07 00:00:00.000000000 Z
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