grape_oauth2 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -11
  3. data/Gemfile +23 -23
  4. data/Rakefile +11 -11
  5. data/grape_oauth2.gemspec +26 -27
  6. data/lib/grape_oauth2.rb +129 -129
  7. data/lib/grape_oauth2/configuration.rb +143 -143
  8. data/lib/grape_oauth2/configuration/class_accessors.rb +36 -36
  9. data/lib/grape_oauth2/configuration/validation.rb +71 -71
  10. data/lib/grape_oauth2/endpoints/authorize.rb +34 -34
  11. data/lib/grape_oauth2/endpoints/token.rb +72 -72
  12. data/lib/grape_oauth2/gem_version.rb +24 -24
  13. data/lib/grape_oauth2/generators/authorization.rb +44 -44
  14. data/lib/grape_oauth2/generators/base.rb +26 -26
  15. data/lib/grape_oauth2/generators/token.rb +62 -62
  16. data/lib/grape_oauth2/helpers/access_token_helpers.rb +52 -54
  17. data/lib/grape_oauth2/helpers/oauth_params.rb +41 -41
  18. data/lib/grape_oauth2/mixins/active_record/access_grant.rb +47 -47
  19. data/lib/grape_oauth2/mixins/active_record/access_token.rb +75 -75
  20. data/lib/grape_oauth2/mixins/active_record/client.rb +36 -35
  21. data/lib/grape_oauth2/mixins/mongoid/access_grant.rb +58 -58
  22. data/lib/grape_oauth2/mixins/mongoid/access_token.rb +88 -88
  23. data/lib/grape_oauth2/mixins/mongoid/client.rb +44 -41
  24. data/lib/grape_oauth2/mixins/sequel/access_grant.rb +68 -68
  25. data/lib/grape_oauth2/mixins/sequel/access_token.rb +86 -86
  26. data/lib/grape_oauth2/mixins/sequel/client.rb +54 -46
  27. data/lib/grape_oauth2/responses/authorization.rb +11 -10
  28. data/lib/grape_oauth2/responses/base.rb +56 -56
  29. data/lib/grape_oauth2/responses/token.rb +10 -10
  30. data/lib/grape_oauth2/scopes.rb +74 -74
  31. data/lib/grape_oauth2/strategies/authorization_code.rb +38 -38
  32. data/lib/grape_oauth2/strategies/base.rb +47 -47
  33. data/lib/grape_oauth2/strategies/client_credentials.rb +20 -20
  34. data/lib/grape_oauth2/strategies/password.rb +22 -22
  35. data/lib/grape_oauth2/strategies/refresh_token.rb +47 -47
  36. data/lib/grape_oauth2/unique_token.rb +20 -20
  37. data/lib/grape_oauth2/version.rb +14 -14
  38. data/spec/configuration/config_spec.rb +231 -231
  39. data/spec/configuration/version_spec.rb +12 -12
  40. data/spec/dummy/endpoints/custom_authorization.rb +25 -25
  41. data/spec/dummy/endpoints/custom_token.rb +35 -35
  42. data/spec/dummy/endpoints/status.rb +25 -25
  43. data/spec/dummy/grape_oauth2_config.rb +11 -11
  44. data/spec/dummy/orm/active_record/app/config/db.rb +7 -7
  45. data/spec/dummy/orm/active_record/app/models/access_code.rb +3 -3
  46. data/spec/dummy/orm/active_record/app/models/access_token.rb +3 -3
  47. data/spec/dummy/orm/active_record/app/models/application.rb +3 -3
  48. data/spec/dummy/orm/active_record/app/models/application_record.rb +3 -3
  49. data/spec/dummy/orm/active_record/app/models/user.rb +10 -10
  50. data/spec/dummy/orm/active_record/app/twitter.rb +36 -36
  51. data/spec/dummy/orm/active_record/config.ru +7 -7
  52. data/spec/dummy/orm/active_record/db/schema.rb +53 -53
  53. data/spec/dummy/orm/mongoid/app/config/db.rb +6 -6
  54. data/spec/dummy/orm/mongoid/app/config/mongoid.yml +21 -21
  55. data/spec/dummy/orm/mongoid/app/models/access_code.rb +3 -3
  56. data/spec/dummy/orm/mongoid/app/models/access_token.rb +3 -3
  57. data/spec/dummy/orm/mongoid/app/models/application.rb +3 -3
  58. data/spec/dummy/orm/mongoid/app/models/user.rb +11 -11
  59. data/spec/dummy/orm/mongoid/app/twitter.rb +34 -34
  60. data/spec/dummy/orm/mongoid/config.ru +5 -5
  61. data/spec/dummy/orm/sequel/app/config/db.rb +1 -1
  62. data/spec/dummy/orm/sequel/app/models/access_code.rb +4 -4
  63. data/spec/dummy/orm/sequel/app/models/access_token.rb +4 -4
  64. data/spec/dummy/orm/sequel/app/models/application.rb +4 -4
  65. data/spec/dummy/orm/sequel/app/models/application_record.rb +2 -2
  66. data/spec/dummy/orm/sequel/app/models/user.rb +11 -11
  67. data/spec/dummy/orm/sequel/app/twitter.rb +47 -47
  68. data/spec/dummy/orm/sequel/config.ru +5 -5
  69. data/spec/dummy/orm/sequel/db/schema.rb +50 -50
  70. data/spec/lib/scopes_spec.rb +50 -50
  71. data/spec/mixins/active_record/access_token_spec.rb +185 -185
  72. data/spec/mixins/active_record/client_spec.rb +104 -95
  73. data/spec/mixins/mongoid/access_token_spec.rb +185 -185
  74. data/spec/mixins/mongoid/client_spec.rb +104 -95
  75. data/spec/mixins/sequel/access_token_spec.rb +185 -185
  76. data/spec/mixins/sequel/client_spec.rb +105 -96
  77. data/spec/requests/flows/authorization_code_spec.rb +67 -67
  78. data/spec/requests/flows/client_credentials_spec.rb +101 -101
  79. data/spec/requests/flows/password_spec.rb +210 -210
  80. data/spec/requests/flows/refresh_token_spec.rb +222 -222
  81. data/spec/requests/flows/revoke_token_spec.rb +103 -103
  82. data/spec/requests/protected_resources_spec.rb +64 -64
  83. data/spec/spec_helper.rb +60 -60
  84. data/spec/support/api_helper.rb +11 -11
  85. metadata +50 -52
  86. data/.rspec +0 -2
  87. data/.rubocop.yml +0 -18
  88. data/.travis.yml +0 -42
  89. data/README.md +0 -820
  90. data/gemfiles/active_record.rb +0 -25
  91. data/gemfiles/mongoid.rb +0 -14
  92. data/gemfiles/sequel.rb +0 -24
  93. data/grape_oauth2.png +0 -0
@@ -1,6 +1,6 @@
1
- Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), :test)
2
-
3
- Mongoid.raise_not_found_error = false
4
-
5
- Mongoid.logger.level = Logger::ERROR
6
- Mongo::Logger.logger.level = Logger::ERROR
1
+ Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), :test)
2
+
3
+ Mongoid.raise_not_found_error = false
4
+
5
+ Mongoid.logger.level = Logger::ERROR
6
+ Mongo::Logger.logger.level = Logger::ERROR
@@ -1,21 +1,21 @@
1
- development:
2
- clients:
3
- default:
4
- database: mongoid-dev
5
- hosts:
6
- - localhost:27017
7
- options:
8
- raise_not_found_error: false
9
- write:
10
- w: 1
11
-
12
- test:
13
- clients:
14
- default:
15
- database: mongoid-test
16
- hosts:
17
- - localhost:27017
18
- options:
19
- raise_not_found_error: false
20
- write:
21
- w: 1
1
+ development:
2
+ clients:
3
+ default:
4
+ database: mongoid-dev
5
+ hosts:
6
+ - localhost:27017
7
+ options:
8
+ raise_not_found_error: false
9
+ write:
10
+ w: 1
11
+
12
+ test:
13
+ clients:
14
+ default:
15
+ database: mongoid-test
16
+ hosts:
17
+ - localhost:27017
18
+ options:
19
+ raise_not_found_error: false
20
+ write:
21
+ w: 1
@@ -1,3 +1,3 @@
1
- class AccessCode
2
- include Grape::OAuth2::Mongoid::AccessGrant
3
- end
1
+ class AccessCode
2
+ include Grape::OAuth2::Mongoid::AccessGrant
3
+ end
@@ -1,3 +1,3 @@
1
- class AccessToken
2
- include Grape::OAuth2::Mongoid::AccessToken
3
- end
1
+ class AccessToken
2
+ include Grape::OAuth2::Mongoid::AccessToken
3
+ end
@@ -1,3 +1,3 @@
1
- class Application
2
- include Grape::OAuth2::Mongoid::Client
3
- end
1
+ class Application
2
+ include Grape::OAuth2::Mongoid::Client
3
+ end
@@ -1,11 +1,11 @@
1
- class User
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- field :username, type: String
6
- field :password, type: String
7
-
8
- def self.oauth_authenticate(_client, username, password)
9
- find_by(username: username, password: password)
10
- end
11
- end
1
+ class User
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :username, type: String
6
+ field :password, type: String
7
+
8
+ def self.oauth_authenticate(_client, username, password)
9
+ find_by(username: username, password: password)
10
+ end
11
+ end
@@ -1,34 +1,34 @@
1
- require 'grape'
2
-
3
- require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
4
-
5
- # Database
6
- load File.expand_path('../config/db.rb', __FILE__)
7
-
8
- # Grape::OAuth2 config
9
- load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
10
-
11
- # Models
12
- require_relative 'models/access_token'
13
- require_relative 'models/access_code'
14
- require_relative 'models/application'
15
- require_relative 'models/user'
16
-
17
- # Twitter Endpoints
18
- require_relative '../../../endpoints/custom_token'
19
- require_relative '../../../endpoints/custom_authorization'
20
- require_relative '../../../endpoints/status'
21
-
22
- module Twitter
23
- class API < Grape::API
24
- version 'v1', using: :path
25
- format :json
26
- prefix :api
27
-
28
- include Grape::OAuth2.api
29
-
30
- mount Twitter::Endpoints::Status
31
- mount Twitter::Endpoints::CustomToken
32
- mount Twitter::Endpoints::CustomAuthorization
33
- end
34
- end
1
+ require 'grape'
2
+
3
+ require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
4
+
5
+ # Database
6
+ load File.expand_path('../config/db.rb', __FILE__)
7
+
8
+ # Grape::OAuth2 config
9
+ load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
10
+
11
+ # Models
12
+ require_relative 'models/access_token'
13
+ require_relative 'models/access_code'
14
+ require_relative 'models/application'
15
+ require_relative 'models/user'
16
+
17
+ # Twitter Endpoints
18
+ require_relative '../../../endpoints/custom_token'
19
+ require_relative '../../../endpoints/custom_authorization'
20
+ require_relative '../../../endpoints/status'
21
+
22
+ module Twitter
23
+ class API < Grape::API
24
+ version 'v1', using: :path
25
+ format :json
26
+ prefix :api
27
+
28
+ include Grape::OAuth2.api
29
+
30
+ mount Twitter::Endpoints::Status
31
+ mount Twitter::Endpoints::CustomToken
32
+ mount Twitter::Endpoints::CustomAuthorization
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- require 'app/twitter'
4
-
5
- run Twitter::API
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'app/twitter'
4
+
5
+ run Twitter::API
@@ -1 +1 @@
1
- load File.expand_path('../../../db/schema.rb', __FILE__)
1
+ load File.expand_path('../../../db/schema.rb', __FILE__)
@@ -1,4 +1,4 @@
1
- class AccessCode < ApplicationRecord
2
- set_dataset :access_codes
3
- include Grape::OAuth2::Sequel::AccessGrant
4
- end
1
+ class AccessCode < ::Sequel::Model
2
+ set_dataset :access_codes
3
+ include Grape::OAuth2::Sequel::AccessGrant
4
+ end
@@ -1,4 +1,4 @@
1
- class AccessToken < ApplicationRecord
2
- set_dataset :access_tokens
3
- include Grape::OAuth2::Sequel::AccessToken
4
- end
1
+ class AccessToken < ::Sequel::Model
2
+ set_dataset :access_tokens
3
+ include Grape::OAuth2::Sequel::AccessToken
4
+ end
@@ -1,4 +1,4 @@
1
- class Application < ApplicationRecord
2
- set_dataset :applications
3
- include Grape::OAuth2::Sequel::Client
4
- end
1
+ class Application < ::Sequel::Model
2
+ set_dataset :applications
3
+ include Grape::OAuth2::Sequel::Client
4
+ end
@@ -1,2 +1,2 @@
1
- class ApplicationRecord < ::Sequel::Model
2
- end
1
+ class ApplicationRecord
2
+ end
@@ -1,11 +1,11 @@
1
- class User < ApplicationRecord
2
- set_dataset :users
3
- plugin :secure_password, include_validations: false
4
-
5
- def self.oauth_authenticate(_client, username, password)
6
- user = find(username: username)
7
- return if user.nil?
8
-
9
- user.authenticate(password)
10
- end
11
- end
1
+ class User < ::Sequel::Model
2
+ set_dataset :users
3
+ plugin :secure_password, include_validations: false
4
+
5
+ def self.oauth_authenticate(_client, username, password)
6
+ user = find(username: username)
7
+ return if user.nil?
8
+
9
+ user.authenticate(password)
10
+ end
11
+ end
@@ -1,47 +1,47 @@
1
- require 'grape'
2
-
3
- require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
4
-
5
- # SQLite memory database
6
- DB = if defined?(JRUBY_VERSION)
7
- Sequel.connect('jdbc:sqlite::memory:')
8
- else
9
- Sequel.sqlite
10
- end
11
-
12
- # Database
13
- load File.expand_path('../config/db.rb', __FILE__)
14
-
15
- # Grape::OAuth2 config
16
- load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
17
-
18
- # Models
19
- require_relative 'models/application_record'
20
- require_relative 'models/access_token'
21
- require_relative 'models/access_code'
22
- require_relative 'models/application'
23
- require_relative 'models/user'
24
-
25
- # Twitter Endpoints
26
- require_relative '../../../endpoints/custom_token'
27
- require_relative '../../../endpoints/custom_authorization'
28
- require_relative '../../../endpoints/status'
29
-
30
- module Twitter
31
- class API < Grape::API
32
- version 'v1', using: :path
33
- format :json
34
- prefix :api
35
-
36
- use *Grape::OAuth2.middleware
37
-
38
- helpers Grape::OAuth2::Helpers::AccessTokenHelpers
39
-
40
- mount Grape::OAuth2::Endpoints::Token
41
- mount Grape::OAuth2::Endpoints::Authorize
42
-
43
- mount Twitter::Endpoints::Status
44
- mount Twitter::Endpoints::CustomToken
45
- mount Twitter::Endpoints::CustomAuthorization
46
- end
47
- end
1
+ require 'grape'
2
+
3
+ require File.expand_path('../../../../../../lib/grape_oauth2', __FILE__)
4
+
5
+ # SQLite memory database
6
+ DB = if defined?(JRUBY_VERSION)
7
+ Sequel.connect('jdbc:sqlite::memory:')
8
+ else
9
+ Sequel.sqlite
10
+ end
11
+
12
+ # Database
13
+ load File.expand_path('../config/db.rb', __FILE__)
14
+
15
+ # Grape::OAuth2 config
16
+ load File.expand_path('../../../../grape_oauth2_config.rb', __FILE__)
17
+
18
+ # Models
19
+ require_relative 'models/application_record'
20
+ require_relative 'models/access_token'
21
+ require_relative 'models/access_code'
22
+ require_relative 'models/application'
23
+ require_relative 'models/user'
24
+
25
+ # Twitter Endpoints
26
+ require_relative '../../../endpoints/custom_token'
27
+ require_relative '../../../endpoints/custom_authorization'
28
+ require_relative '../../../endpoints/status'
29
+
30
+ module Twitter
31
+ class API < Grape::API
32
+ version 'v1', using: :path
33
+ format :json
34
+ prefix :api
35
+
36
+ use *Grape::OAuth2.middleware
37
+
38
+ helpers Grape::OAuth2::Helpers::AccessTokenHelpers
39
+
40
+ mount Grape::OAuth2::Endpoints::Token
41
+ mount Grape::OAuth2::Endpoints::Authorize
42
+
43
+ mount Twitter::Endpoints::Status
44
+ mount Twitter::Endpoints::CustomToken
45
+ mount Twitter::Endpoints::CustomAuthorization
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- require 'app/twitter'
4
-
5
- run Twitter::API
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'app/twitter'
4
+
5
+ run Twitter::API
@@ -1,50 +1,50 @@
1
- DB.create_table :applications do
2
- primary_key :id
3
-
4
- column :name, String, size: 255, null: false
5
- column :key, String, size: 255, null: false, index: { unique: true }
6
- column :secret, String, size: 255, null: false
7
-
8
-
9
- column :redirect_uri, String
10
-
11
- column :created_at, DateTime
12
- column :updated_at, DateTime
13
- end
14
-
15
- DB.create_table :access_tokens do
16
- primary_key :id
17
- column :client_id, Integer
18
- column :resource_owner_id, Integer, index: true
19
-
20
- column :token, String, size: 255, null: false, index: { unique: true }
21
-
22
- column :refresh_token, String, size: 255, index: { unique: true }
23
-
24
- column :expires_at, DateTime
25
- column :revoked_at, DateTime
26
- column :created_at, DateTime, null: false
27
- column :scopes, String, size: 255
28
- end
29
-
30
- DB.create_table :access_codes do
31
- primary_key :id
32
- column :client_id, Integer
33
- column :resource_owner_id, Integer, index: true
34
-
35
- column :token, String, size: 255, null: false, index: { unique: true }
36
- column :redirect_uri, String, size: 255, index: { unique: true }
37
-
38
- column :expires_at, DateTime
39
- column :created_at, DateTime, null: false
40
- column :scopes, String, size: 255
41
- end
42
-
43
- DB.create_table :users do
44
- primary_key :id
45
- column :name, String, size: 255
46
- column :username, String, size: 255
47
- column :created_at, DateTime
48
- column :updated_at, DateTime
49
- column :password_digest, String, size: 255
50
- end
1
+ DB.create_table :applications do
2
+ primary_key :id
3
+
4
+ column :name, String, size: 255, null: false
5
+ column :key, String, size: 255, null: false, index: { unique: true }
6
+ column :secret, String, size: 255, null: false
7
+
8
+
9
+ column :redirect_uri, String
10
+
11
+ column :created_at, DateTime
12
+ column :updated_at, DateTime
13
+ end
14
+
15
+ DB.create_table :access_tokens do
16
+ primary_key :id
17
+ column :client_id, Integer
18
+ column :resource_owner_id, Integer, index: true
19
+
20
+ column :token, String, size: 255, null: false, index: { unique: true }
21
+
22
+ column :refresh_token, String, size: 255, index: { unique: true }
23
+
24
+ column :expires_at, DateTime
25
+ column :revoked_at, DateTime
26
+ column :created_at, DateTime, null: false
27
+ column :scopes, String, size: 255
28
+ end
29
+
30
+ DB.create_table :access_codes do
31
+ primary_key :id
32
+ column :client_id, Integer
33
+ column :resource_owner_id, Integer, index: true
34
+
35
+ column :token, String, size: 255, null: false, index: { unique: true }
36
+ column :redirect_uri, String, size: 255, index: { unique: true }
37
+
38
+ column :expires_at, DateTime
39
+ column :created_at, DateTime, null: false
40
+ column :scopes, String, size: 255
41
+ end
42
+
43
+ DB.create_table :users do
44
+ primary_key :id
45
+ column :name, String, size: 255
46
+ column :username, String, size: 255
47
+ column :created_at, DateTime
48
+ column :updated_at, DateTime
49
+ column :password_digest, String, size: 255
50
+ end