grape_oauth2 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/.gitignore +11 -11
- data/Gemfile +23 -23
- data/Rakefile +11 -11
- data/grape_oauth2.gemspec +26 -27
- data/lib/grape_oauth2.rb +129 -129
- data/lib/grape_oauth2/configuration.rb +143 -143
- data/lib/grape_oauth2/configuration/class_accessors.rb +36 -36
- data/lib/grape_oauth2/configuration/validation.rb +71 -71
- data/lib/grape_oauth2/endpoints/authorize.rb +34 -34
- data/lib/grape_oauth2/endpoints/token.rb +72 -72
- data/lib/grape_oauth2/gem_version.rb +24 -24
- data/lib/grape_oauth2/generators/authorization.rb +44 -44
- data/lib/grape_oauth2/generators/base.rb +26 -26
- data/lib/grape_oauth2/generators/token.rb +62 -62
- data/lib/grape_oauth2/helpers/access_token_helpers.rb +52 -54
- data/lib/grape_oauth2/helpers/oauth_params.rb +41 -41
- data/lib/grape_oauth2/mixins/active_record/access_grant.rb +47 -47
- data/lib/grape_oauth2/mixins/active_record/access_token.rb +75 -75
- data/lib/grape_oauth2/mixins/active_record/client.rb +36 -35
- data/lib/grape_oauth2/mixins/mongoid/access_grant.rb +58 -58
- data/lib/grape_oauth2/mixins/mongoid/access_token.rb +88 -88
- data/lib/grape_oauth2/mixins/mongoid/client.rb +44 -41
- data/lib/grape_oauth2/mixins/sequel/access_grant.rb +68 -68
- data/lib/grape_oauth2/mixins/sequel/access_token.rb +86 -86
- data/lib/grape_oauth2/mixins/sequel/client.rb +54 -46
- data/lib/grape_oauth2/responses/authorization.rb +11 -10
- data/lib/grape_oauth2/responses/base.rb +56 -56
- data/lib/grape_oauth2/responses/token.rb +10 -10
- data/lib/grape_oauth2/scopes.rb +74 -74
- data/lib/grape_oauth2/strategies/authorization_code.rb +38 -38
- data/lib/grape_oauth2/strategies/base.rb +47 -47
- data/lib/grape_oauth2/strategies/client_credentials.rb +20 -20
- data/lib/grape_oauth2/strategies/password.rb +22 -22
- data/lib/grape_oauth2/strategies/refresh_token.rb +47 -47
- data/lib/grape_oauth2/unique_token.rb +20 -20
- data/lib/grape_oauth2/version.rb +14 -14
- data/spec/configuration/config_spec.rb +231 -231
- data/spec/configuration/version_spec.rb +12 -12
- data/spec/dummy/endpoints/custom_authorization.rb +25 -25
- data/spec/dummy/endpoints/custom_token.rb +35 -35
- data/spec/dummy/endpoints/status.rb +25 -25
- data/spec/dummy/grape_oauth2_config.rb +11 -11
- data/spec/dummy/orm/active_record/app/config/db.rb +7 -7
- data/spec/dummy/orm/active_record/app/models/access_code.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/access_token.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/application.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/application_record.rb +3 -3
- data/spec/dummy/orm/active_record/app/models/user.rb +10 -10
- data/spec/dummy/orm/active_record/app/twitter.rb +36 -36
- data/spec/dummy/orm/active_record/config.ru +7 -7
- data/spec/dummy/orm/active_record/db/schema.rb +53 -53
- data/spec/dummy/orm/mongoid/app/config/db.rb +6 -6
- data/spec/dummy/orm/mongoid/app/config/mongoid.yml +21 -21
- data/spec/dummy/orm/mongoid/app/models/access_code.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/access_token.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/application.rb +3 -3
- data/spec/dummy/orm/mongoid/app/models/user.rb +11 -11
- data/spec/dummy/orm/mongoid/app/twitter.rb +34 -34
- data/spec/dummy/orm/mongoid/config.ru +5 -5
- data/spec/dummy/orm/sequel/app/config/db.rb +1 -1
- data/spec/dummy/orm/sequel/app/models/access_code.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/access_token.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/application.rb +4 -4
- data/spec/dummy/orm/sequel/app/models/application_record.rb +2 -2
- data/spec/dummy/orm/sequel/app/models/user.rb +11 -11
- data/spec/dummy/orm/sequel/app/twitter.rb +47 -47
- data/spec/dummy/orm/sequel/config.ru +5 -5
- data/spec/dummy/orm/sequel/db/schema.rb +50 -50
- data/spec/lib/scopes_spec.rb +50 -50
- data/spec/mixins/active_record/access_token_spec.rb +185 -185
- data/spec/mixins/active_record/client_spec.rb +104 -95
- data/spec/mixins/mongoid/access_token_spec.rb +185 -185
- data/spec/mixins/mongoid/client_spec.rb +104 -95
- data/spec/mixins/sequel/access_token_spec.rb +185 -185
- data/spec/mixins/sequel/client_spec.rb +105 -96
- data/spec/requests/flows/authorization_code_spec.rb +67 -67
- data/spec/requests/flows/client_credentials_spec.rb +101 -101
- data/spec/requests/flows/password_spec.rb +210 -210
- data/spec/requests/flows/refresh_token_spec.rb +222 -222
- data/spec/requests/flows/revoke_token_spec.rb +103 -103
- data/spec/requests/protected_resources_spec.rb +64 -64
- data/spec/spec_helper.rb +60 -60
- data/spec/support/api_helper.rb +11 -11
- metadata +50 -52
- data/.rspec +0 -2
- data/.rubocop.yml +0 -18
- data/.travis.yml +0 -42
- data/README.md +0 -820
- data/gemfiles/active_record.rb +0 -25
- data/gemfiles/mongoid.rb +0 -14
- data/gemfiles/sequel.rb +0 -24
- data/grape_oauth2.png +0 -0
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Grape::OAuth2 Version' do
|
4
|
-
it 'has a version string' do
|
5
|
-
expect(Grape::OAuth2::VERSION::STRING).to be_present
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns version as an instance of Gem::Version' do
|
9
|
-
expect(Grape::OAuth2.gem_version).to be_an_instance_of(Gem::Version)
|
10
|
-
expect(Grape::OAuth2.version).to be_an_instance_of(Gem::Version)
|
11
|
-
end
|
12
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Grape::OAuth2 Version' do
|
4
|
+
it 'has a version string' do
|
5
|
+
expect(Grape::OAuth2::VERSION::STRING).to be_present
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns version as an instance of Gem::Version' do
|
9
|
+
expect(Grape::OAuth2.gem_version).to be_an_instance_of(Gem::Version)
|
10
|
+
expect(Grape::OAuth2.version).to be_an_instance_of(Gem::Version)
|
11
|
+
end
|
12
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module Twitter
|
2
|
-
module Endpoints
|
3
|
-
class CustomAuthorization < ::Grape::API
|
4
|
-
helpers Grape::OAuth2::Helpers::OAuthParams
|
5
|
-
|
6
|
-
namespace :oauth do
|
7
|
-
params do
|
8
|
-
use :oauth_authorization_params
|
9
|
-
end
|
10
|
-
|
11
|
-
post :custom_authorize do
|
12
|
-
response = Grape::OAuth2::Generators::Authorization.generate_for(env) do |request, response|
|
13
|
-
request.unsupported_response_type!
|
14
|
-
end
|
15
|
-
|
16
|
-
# Status
|
17
|
-
status response.status
|
18
|
-
|
19
|
-
# Body
|
20
|
-
body response.body
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module Twitter
|
2
|
+
module Endpoints
|
3
|
+
class CustomAuthorization < ::Grape::API
|
4
|
+
helpers Grape::OAuth2::Helpers::OAuthParams
|
5
|
+
|
6
|
+
namespace :oauth do
|
7
|
+
params do
|
8
|
+
use :oauth_authorization_params
|
9
|
+
end
|
10
|
+
|
11
|
+
post :custom_authorize do
|
12
|
+
response = Grape::OAuth2::Generators::Authorization.generate_for(env) do |request, response|
|
13
|
+
request.unsupported_response_type!
|
14
|
+
end
|
15
|
+
|
16
|
+
# Status
|
17
|
+
status response.status
|
18
|
+
|
19
|
+
# Body
|
20
|
+
body response.body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
module Twitter
|
2
|
-
module Endpoints
|
3
|
-
class CustomToken < ::Grape::API
|
4
|
-
helpers Grape::OAuth2::Helpers::OAuthParams
|
5
|
-
|
6
|
-
namespace :oauth do
|
7
|
-
params do
|
8
|
-
use :oauth_token_params
|
9
|
-
end
|
10
|
-
|
11
|
-
post :custom_token do
|
12
|
-
token_response = Grape::OAuth2::Generators::Token.generate_for(env) do |request, response|
|
13
|
-
# Custom client authentication:
|
14
|
-
client = Grape::OAuth2::Strategies::Base.authenticate_client(request)
|
15
|
-
request.invalid_client! if client.nil? || client.name != 'Admin'
|
16
|
-
|
17
|
-
resource_owner = Grape::OAuth2::Strategies::Base.authenticate_resource_owner(client, request)
|
18
|
-
request.invalid_grant! if resource_owner.nil?
|
19
|
-
|
20
|
-
token = AccessToken.create_for(client, resource_owner, request.scope.join(' '))
|
21
|
-
response.access_token = Grape::OAuth2::Strategies::Base.expose_to_bearer_token(token)
|
22
|
-
end
|
23
|
-
|
24
|
-
status token_response.status
|
25
|
-
|
26
|
-
token_response.headers.each do |key, value|
|
27
|
-
header key, value
|
28
|
-
end
|
29
|
-
|
30
|
-
body token_response.body
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
module Twitter
|
2
|
+
module Endpoints
|
3
|
+
class CustomToken < ::Grape::API
|
4
|
+
helpers Grape::OAuth2::Helpers::OAuthParams
|
5
|
+
|
6
|
+
namespace :oauth do
|
7
|
+
params do
|
8
|
+
use :oauth_token_params
|
9
|
+
end
|
10
|
+
|
11
|
+
post :custom_token do
|
12
|
+
token_response = Grape::OAuth2::Generators::Token.generate_for(env) do |request, response|
|
13
|
+
# Custom client authentication:
|
14
|
+
client = Grape::OAuth2::Strategies::Base.authenticate_client(request)
|
15
|
+
request.invalid_client! if client.nil? || client.name != 'Admin'
|
16
|
+
|
17
|
+
resource_owner = Grape::OAuth2::Strategies::Base.authenticate_resource_owner(client, request)
|
18
|
+
request.invalid_grant! if resource_owner.nil?
|
19
|
+
|
20
|
+
token = AccessToken.create_for(client, resource_owner, request.scope.join(' '))
|
21
|
+
response.access_token = Grape::OAuth2::Strategies::Base.expose_to_bearer_token(token)
|
22
|
+
end
|
23
|
+
|
24
|
+
status token_response.status
|
25
|
+
|
26
|
+
token_response.headers.each do |key, value|
|
27
|
+
header key, value
|
28
|
+
end
|
29
|
+
|
30
|
+
body token_response.body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
module Twitter
|
2
|
-
module Endpoints
|
3
|
-
class Status < Grape::API
|
4
|
-
before do
|
5
|
-
access_token_required!
|
6
|
-
end
|
7
|
-
|
8
|
-
resources :status do
|
9
|
-
get do
|
10
|
-
{ value: 'Nice day!', current_user: current_resource_owner.username }
|
11
|
-
end
|
12
|
-
|
13
|
-
get :single_scope, scopes: [:read] do
|
14
|
-
{ value: 'Access granted' }
|
15
|
-
end
|
16
|
-
|
17
|
-
get :multiple_scopes, scopes: [:read, :write] do
|
18
|
-
access_token_required!
|
19
|
-
|
20
|
-
{ value: 'Access granted' }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module Twitter
|
2
|
+
module Endpoints
|
3
|
+
class Status < Grape::API
|
4
|
+
before do
|
5
|
+
access_token_required!
|
6
|
+
end
|
7
|
+
|
8
|
+
resources :status do
|
9
|
+
get do
|
10
|
+
{ value: 'Nice day!', current_user: current_resource_owner.username }
|
11
|
+
end
|
12
|
+
|
13
|
+
get :single_scope, scopes: [:read] do
|
14
|
+
{ value: 'Access granted' }
|
15
|
+
end
|
16
|
+
|
17
|
+
get :multiple_scopes, scopes: [:read, :write] do
|
18
|
+
access_token_required!
|
19
|
+
|
20
|
+
{ value: 'Access granted' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
# Common config across all the ORMs
|
2
|
-
Grape::OAuth2.configure do |config|
|
3
|
-
config.client_class_name = 'Application'
|
4
|
-
config.access_token_class_name = 'AccessToken'
|
5
|
-
config.resource_owner_class_name = 'User'
|
6
|
-
config.access_grant_class_name = 'AccessCode'
|
7
|
-
|
8
|
-
config.realm = 'Custom Realm'
|
9
|
-
|
10
|
-
config.allowed_grant_types << 'refresh_token'
|
11
|
-
end
|
1
|
+
# Common config across all the ORMs
|
2
|
+
Grape::OAuth2.configure do |config|
|
3
|
+
config.client_class_name = 'Application'
|
4
|
+
config.access_token_class_name = 'AccessToken'
|
5
|
+
config.resource_owner_class_name = 'User'
|
6
|
+
config.access_grant_class_name = 'AccessCode'
|
7
|
+
|
8
|
+
config.realm = 'Custom Realm'
|
9
|
+
|
10
|
+
config.allowed_grant_types << 'refresh_token'
|
11
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:')
|
2
|
-
|
3
|
-
::ActiveRecord::Base.default_timezone = :utc
|
4
|
-
::ActiveRecord::Base.logger = ENV['RAILS_ENV'] == 'test' ? nil : Logger.new(STDOUT)
|
5
|
-
|
6
|
-
::ActiveRecord::Migration.verbose = false
|
7
|
-
load File.expand_path('../../../db/schema.rb', __FILE__)
|
1
|
+
OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:')
|
2
|
+
|
3
|
+
::ActiveRecord::Base.default_timezone = :utc
|
4
|
+
::ActiveRecord::Base.logger = ENV['RAILS_ENV'] == 'test' ? nil : Logger.new(STDOUT)
|
5
|
+
|
6
|
+
::ActiveRecord::Migration.verbose = false
|
7
|
+
load File.expand_path('../../../db/schema.rb', __FILE__)
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class AccessCode < ApplicationRecord
|
2
|
-
include Grape::OAuth2::ActiveRecord::AccessGrant
|
3
|
-
end
|
1
|
+
class AccessCode < ApplicationRecord
|
2
|
+
include Grape::OAuth2::ActiveRecord::AccessGrant
|
3
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class AccessToken < ApplicationRecord
|
2
|
-
include Grape::OAuth2::ActiveRecord::AccessToken
|
3
|
-
end
|
1
|
+
class AccessToken < ApplicationRecord
|
2
|
+
include Grape::OAuth2::ActiveRecord::AccessToken
|
3
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class Application < ApplicationRecord
|
2
|
-
include Grape::OAuth2::ActiveRecord::Client
|
3
|
-
end
|
1
|
+
class Application < ApplicationRecord
|
2
|
+
include Grape::OAuth2::ActiveRecord::Client
|
3
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class ApplicationRecord < ::ActiveRecord::Base
|
2
|
-
self.abstract_class = true
|
3
|
-
end
|
1
|
+
class ApplicationRecord < ::ActiveRecord::Base
|
2
|
+
self.abstract_class = true
|
3
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class User < ApplicationRecord
|
2
|
-
has_secure_password
|
3
|
-
|
4
|
-
def self.oauth_authenticate(_client, username, password)
|
5
|
-
user = find_by(username: username)
|
6
|
-
return if user.nil?
|
7
|
-
|
8
|
-
user.authenticate(password)
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class User < ApplicationRecord
|
2
|
+
has_secure_password
|
3
|
+
|
4
|
+
def self.oauth_authenticate(_client, username, password)
|
5
|
+
user = find_by(username: username)
|
6
|
+
return if user.nil?
|
7
|
+
|
8
|
+
user.authenticate(password)
|
9
|
+
end
|
10
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
require 'otr-activerecord'
|
2
|
-
require 'grape'
|
3
|
-
|
4
|
-
require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
|
5
|
-
|
6
|
-
# Database
|
7
|
-
load File.expand_path('../config/db.rb', __FILE__)
|
8
|
-
|
9
|
-
# Grape::OAuth2 config
|
10
|
-
load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
|
11
|
-
|
12
|
-
# Models
|
13
|
-
require_relative 'models/application_record'
|
14
|
-
require_relative 'models/access_token'
|
15
|
-
require_relative 'models/access_code'
|
16
|
-
require_relative 'models/application'
|
17
|
-
require_relative 'models/user'
|
18
|
-
|
19
|
-
# Twitter Endpoints
|
20
|
-
require_relative '../../../endpoints/custom_token'
|
21
|
-
require_relative '../../../endpoints/custom_authorization'
|
22
|
-
require_relative '../../../endpoints/status'
|
23
|
-
|
24
|
-
module Twitter
|
25
|
-
class API < Grape::API
|
26
|
-
version 'v1', using: :path
|
27
|
-
format :json
|
28
|
-
prefix :api
|
29
|
-
|
30
|
-
include Grape::OAuth2.api
|
31
|
-
|
32
|
-
mount Twitter::Endpoints::Status
|
33
|
-
mount Twitter::Endpoints::CustomToken
|
34
|
-
mount Twitter::Endpoints::CustomAuthorization
|
35
|
-
end
|
36
|
-
end
|
1
|
+
require 'otr-activerecord'
|
2
|
+
require 'grape'
|
3
|
+
|
4
|
+
require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
|
5
|
+
|
6
|
+
# Database
|
7
|
+
load File.expand_path('../config/db.rb', __FILE__)
|
8
|
+
|
9
|
+
# Grape::OAuth2 config
|
10
|
+
load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
|
11
|
+
|
12
|
+
# Models
|
13
|
+
require_relative 'models/application_record'
|
14
|
+
require_relative 'models/access_token'
|
15
|
+
require_relative 'models/access_code'
|
16
|
+
require_relative 'models/application'
|
17
|
+
require_relative 'models/user'
|
18
|
+
|
19
|
+
# Twitter Endpoints
|
20
|
+
require_relative '../../../endpoints/custom_token'
|
21
|
+
require_relative '../../../endpoints/custom_authorization'
|
22
|
+
require_relative '../../../endpoints/status'
|
23
|
+
|
24
|
+
module Twitter
|
25
|
+
class API < Grape::API
|
26
|
+
version 'v1', using: :path
|
27
|
+
format :json
|
28
|
+
prefix :api
|
29
|
+
|
30
|
+
include Grape::OAuth2.api
|
31
|
+
|
32
|
+
mount Twitter::Endpoints::Status
|
33
|
+
mount Twitter::Endpoints::CustomToken
|
34
|
+
mount Twitter::Endpoints::CustomAuthorization
|
35
|
+
end
|
36
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
require 'app/twitter'
|
4
|
-
|
5
|
-
use OTR::ActiveRecord::ConnectionManagement
|
6
|
-
|
7
|
-
run Twitter::API
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'app/twitter'
|
4
|
+
|
5
|
+
use OTR::ActiveRecord::ConnectionManagement
|
6
|
+
|
7
|
+
run Twitter::API
|
@@ -1,53 +1,53 @@
|
|
1
|
-
ActiveRecord::Schema.define(version: 3) do
|
2
|
-
create_table :users do |t|
|
3
|
-
t.string :name
|
4
|
-
t.string :username
|
5
|
-
t.string :password_digest
|
6
|
-
end
|
7
|
-
|
8
|
-
create_table :applications do |t|
|
9
|
-
t.string :name
|
10
|
-
t.string :key
|
11
|
-
t.string :secret
|
12
|
-
t.string :redirect_uri
|
13
|
-
|
14
|
-
t.timestamps null: false
|
15
|
-
end
|
16
|
-
|
17
|
-
add_index :applications, :key, unique: true
|
18
|
-
|
19
|
-
create_table :access_tokens do |t|
|
20
|
-
t.integer :resource_owner_id
|
21
|
-
t.integer :client_id
|
22
|
-
|
23
|
-
t.string :token, null: false
|
24
|
-
t.string :refresh_token
|
25
|
-
t.string :scopes
|
26
|
-
|
27
|
-
t.datetime :expires_at
|
28
|
-
t.datetime :revoked_at
|
29
|
-
t.datetime :created_at, null: false
|
30
|
-
end
|
31
|
-
|
32
|
-
create_table :access_codes do |t|
|
33
|
-
t.integer :resource_owner_id
|
34
|
-
t.integer :client_id
|
35
|
-
|
36
|
-
t.string :token, null: false
|
37
|
-
t.string :redirect_uri
|
38
|
-
t.string :scopes
|
39
|
-
|
40
|
-
t.datetime :expires_at
|
41
|
-
t.datetime :revoked_at
|
42
|
-
t.datetime :created_at, null: false
|
43
|
-
end
|
44
|
-
|
45
|
-
add_index :access_tokens, :token, unique: true
|
46
|
-
add_index :access_tokens, :resource_owner_id
|
47
|
-
add_index :access_tokens, :client_id
|
48
|
-
add_index :access_tokens, :refresh_token, unique: true
|
49
|
-
|
50
|
-
add_index :access_codes, :token, unique: true
|
51
|
-
add_index :access_codes, :resource_owner_id
|
52
|
-
add_index :access_codes, :client_id
|
53
|
-
end
|
1
|
+
ActiveRecord::Schema.define(version: 3) do
|
2
|
+
create_table :users do |t|
|
3
|
+
t.string :name
|
4
|
+
t.string :username
|
5
|
+
t.string :password_digest
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :applications do |t|
|
9
|
+
t.string :name
|
10
|
+
t.string :key
|
11
|
+
t.string :secret
|
12
|
+
t.string :redirect_uri
|
13
|
+
|
14
|
+
t.timestamps null: false
|
15
|
+
end
|
16
|
+
|
17
|
+
add_index :applications, :key, unique: true
|
18
|
+
|
19
|
+
create_table :access_tokens do |t|
|
20
|
+
t.integer :resource_owner_id
|
21
|
+
t.integer :client_id
|
22
|
+
|
23
|
+
t.string :token, null: false
|
24
|
+
t.string :refresh_token
|
25
|
+
t.string :scopes
|
26
|
+
|
27
|
+
t.datetime :expires_at
|
28
|
+
t.datetime :revoked_at
|
29
|
+
t.datetime :created_at, null: false
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table :access_codes do |t|
|
33
|
+
t.integer :resource_owner_id
|
34
|
+
t.integer :client_id
|
35
|
+
|
36
|
+
t.string :token, null: false
|
37
|
+
t.string :redirect_uri
|
38
|
+
t.string :scopes
|
39
|
+
|
40
|
+
t.datetime :expires_at
|
41
|
+
t.datetime :revoked_at
|
42
|
+
t.datetime :created_at, null: false
|
43
|
+
end
|
44
|
+
|
45
|
+
add_index :access_tokens, :token, unique: true
|
46
|
+
add_index :access_tokens, :resource_owner_id
|
47
|
+
add_index :access_tokens, :client_id
|
48
|
+
add_index :access_tokens, :refresh_token, unique: true
|
49
|
+
|
50
|
+
add_index :access_codes, :token, unique: true
|
51
|
+
add_index :access_codes, :resource_owner_id
|
52
|
+
add_index :access_codes, :client_id
|
53
|
+
end
|