arkaan 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c1ec575ec3457e7920d4ba8adc017667cc6703e
4
- data.tar.gz: 977526cae9348564d8e3e14674c73646a7b522a5
3
+ metadata.gz: 4ac83b9b70e1ecb3bca72b55a576c6c73f09b941
4
+ data.tar.gz: 6b6e2d509bd95684032a0553807255cbed1209eb
5
5
  SHA512:
6
- metadata.gz: 28c7cecdc80476e4e624d7b5cbc37a8d12456ef0667a4c01586efcc4146068bc2930f81db9c8a3bb8415930f7e73e44bc8272cfa394246581a668b28c6895d81
7
- data.tar.gz: 0126a61e8bc40fc9e8b4172084515a82f08720380f01b49fb1cad9aae2c27de6790939b9a187be620dae92c9d71774f96aceb036496c0cb3009e0acab2b6e874
6
+ metadata.gz: 3e2f8ef7eddb21380844592ae7c9c0a1380a19db6a42d44b567caba5a35c46dc5e791d3eb6f35bdf47c1f70c0a9ac6633b3b281b8f778108f04ffa273d9da312
7
+ data.tar.gz: 132672eacf3f19613cb58c6929f5d04575191a0a3a17e57c23897511491371d94a992767951d7508e2ca6161fe6144aea0d254eca067b76afce4eb0e24039886
@@ -8,4 +8,5 @@ module Arkaan
8
8
  autoload :Account , 'arkaan/account'
9
9
  autoload :Permissions, 'arkaan/permissions'
10
10
  autoload :Concerns , 'arkaan/concerns'
11
+ autoload :OAuth , 'arkaan/oauth'
11
12
  end
@@ -25,18 +25,24 @@ module Arkaan
25
25
  # @return [String] the email address of the user, useful to contact them ; it must be given, unique, and have an email format.
26
26
  field :email, type: String
27
27
 
28
+ # @!attribute [w] password
29
+ # @return [String] password, in clear, of the user ; do not attempt to get the value, just set it when changing the password.
30
+ # @!attribute [w] password_confirmation
31
+ # @return [String] the confirmation of the password, do not get, just set it ; it must be the same as the password.
32
+ has_secure_password
33
+
28
34
  # @!attribute [rw] groups
29
35
  # @return [Array<Arkaan::Permissions::Group>] the groups giving their corresponding rights to the current account.
30
36
  has_and_belongs_to_many :groups, class_name: 'Arkaan::Permissions::Group', inverse_of: :accounts
37
+ # @!attribute [rw] applications
38
+ # @return [Array<Arkaan::OAuth::Application] the applications this user has created and owns.
39
+ has_many :applications, class_name: 'Arkaan::OAuth::Application', inverse_of: :creator
40
+ # @!attribute [rw] authorizations
41
+ # @return [Array<Arkaan::OAuth::Authorization>] the authorization issued by this account to third-party applications to access its data.
42
+ has_many :authorizations, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :account
31
43
 
32
44
  validates :username, length: {minimum: 6}, uniqueness: true
33
45
 
34
46
  validates :email, presence: true, format: {with: /\A[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}\z/}, uniqueness: true
35
-
36
- # @!attribute [w] password
37
- # @return [String] password, in clear, of the user ; do not attempt to get the value, just set it when changing the password.
38
- # @!attribute [w] password_confirmation
39
- # @return [String] the confirmation of the password, do not get, just set it ; it must be the same as the password.
40
- has_secure_password
41
47
  end
42
48
  end
@@ -0,0 +1,10 @@
1
+ module Arkaan
2
+ # This module holds the logic for the connection of an application to our API.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ module OAuth
5
+ autoload :Application , 'arkaan/oauth/application'
6
+ autoload :Authorization, 'arkaan/oauth/authorization'
7
+ autoload :AccessToken , 'arkaan/oauth/access_token'
8
+ autoload :RefreshToken , 'arkaan/oauth/refresh_token'
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ module Arkaan
2
+ module OAuth
3
+ # An access token is the value assigned to the application to access the private data of an account.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class AccessToken
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] value
10
+ # @return [String] the value of the token, returned to the application when built.
11
+ field :value, type: String, default: ->{ SecureRandom.hex }
12
+ # @!attribute [rw] expiration
13
+ # @return [Integer] the time, in seconds, after which the token is declared expired, and thus can't be used anymore.
14
+ field :expiration, type: Integer, default: 86400
15
+
16
+ # @!attribute [rw] authorization
17
+ # @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application for this user.
18
+ belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :access_token
19
+
20
+ validates :value, presence: true, uniqueness: true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module Arkaan
2
+ module OAuth
3
+ # An application is what is referred to in the OAuth2.0 RFC as a client, wanting to access private informations about the user.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Application
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] name
10
+ # @return [String] the unique name of the application, mainly used to identify and display it.
11
+ field :name, type: String
12
+ # @!attribute [rw] key
13
+ # @return [String] the unique key for the application, identifying it when requesting a token for the API.
14
+ field :key, type: String, default: ->{ SecureRandom.hex }
15
+ # @!attribute [rw] premium
16
+ # @return [Boolean] a value indicating whether the application should automatically receive a token when an account is created, or not.
17
+ field :premium, type: Boolean, default: false
18
+
19
+ # @!attribute [rw] creator
20
+ # @return [Arkaan::Account] the account that has created this application, considered its owner.
21
+ belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :applications
22
+ # @!attribute [rw] authorizations
23
+ # @return [Array<Arkaan::OAuth::Authorization>] the authorizations linked to the accounts this application can get the data from.
24
+ has_many :authorizations, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :application
25
+
26
+ validates :name, presence: true, length: {minimum: 6}, uniqueness: true
27
+
28
+ validates :key, presence: true, uniqueness: true
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ module Arkaan
2
+ module OAuth
3
+ # An OAuth authorization is granted by a user to an application to access its personal data.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Authorization
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] code
10
+ # @return [String] the value corresponding to the authentication code in the RFC of OAuth2.0, kep for historic purpose.
11
+ field :code, type: String, default: ->{ SecureRandom.hex }
12
+
13
+ # @!attribute [rw] account
14
+ # @return [Arkaaan::Account] the account granting the authorization to access its data to the application.
15
+ belongs_to :account, class_name: 'Arkaan::Account', inverse_of: :authorizations
16
+ # @!attribute [rw] application
17
+ # @return [Arkaan::OAuth::Application] the application asking to access account's data.
18
+ belongs_to :application, class_name: 'Arkaan::OAuth::Application', inverse_of: :authorizations
19
+ # @!attribute [rw] token
20
+ # @return [Arkaan::OAuth::AccessToken] the access token used further in the application process to access private data of the account.
21
+ has_one :token, class_name: 'Arkaan::OAuth::AccessToken', inverse_of: :authorization
22
+
23
+ validates :code, presence: true, uniqueness: true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ module Arkaan
2
+ module OAuth
3
+ # A refresh token is used when an access token is expired, to get a new one. It is then recreated for the next expiration.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class RefreshToken
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps
8
+
9
+ # @!attribute [rw] value
10
+ # @return [String] the value of the token, returned to the application when built.
11
+ field :value, type: String, default: ->{ SecureRandom.hex }
12
+
13
+ # @!attribute [rw] authorization
14
+ # @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application for this user.
15
+ belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :refresh_token
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-19 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -160,6 +160,11 @@ files:
160
160
  - lib/arkaan/account.rb
161
161
  - lib/arkaan/concerns.rb
162
162
  - lib/arkaan/concerns/sluggable.rb
163
+ - lib/arkaan/oauth.rb
164
+ - lib/arkaan/oauth/access_token.rb
165
+ - lib/arkaan/oauth/application.rb
166
+ - lib/arkaan/oauth/authorization.rb
167
+ - lib/arkaan/oauth/refresh_token.rb
163
168
  - lib/arkaan/permissions.rb
164
169
  - lib/arkaan/permissions/category.rb
165
170
  - lib/arkaan/permissions/group.rb