Class: Oauth2Provider::Client
- Inherits:
-
Object
- Object
- Oauth2Provider::Client
- Includes:
- Mongoid::Document, Mongoid::Timestamps, Document::Base
- Defined in:
- app/models/oauth2_provider/client.rb
Class Method Summary collapse
-
.sync_clients_with_scope(scope) ⇒ Object
Sync all clients with the correct exploded scope when a scope is modified (changed or removed).
-
.where_scope(scope) ⇒ Object
Filter to the client scope.
-
.where_secret(secret, client_uri) ⇒ Object
Filter to the client secret and the redirect uri.
-
.where_uri(client_uri, redirect_uri) ⇒ Object
Filter to the client uri (internal identifier) and the redirect uri.
Instance Method Summary collapse
-
#block! ⇒ Object
Block the client.
-
#blocked? ⇒ Boolean
Check if the status is or is not blocked.
-
#granted! ⇒ Object
Increase the counter of resource owners granting the access to the client.
-
#revoked! ⇒ Object
Increase the counter of resource owners revoking the access to the client.
- #scope_pretty ⇒ Object
- #scope_values_pretty ⇒ Object
-
#unblock! ⇒ Object
Unblock the client.
Methods included from Document::Base
Class Method Details
.sync_clients_with_scope(scope) ⇒ Object
Sync all clients with the correct exploded scope when a scope is modified (changed or removed)
97 98 99 100 101 102 103 |
# File 'app/models/oauth2_provider/client.rb', line 97 def sync_clients_with_scope(scope) Client.all.each do |client| scope_string = client.scope.join(Oauth2Provider.settings["scope_separator"]) client.scope_values = Oauth2Provider.normalize_scope(scope_string) client.save end end |
.where_scope(scope) ⇒ Object
Filter to the client scope
91 92 93 |
# File 'app/models/oauth2_provider/client.rb', line 91 def where_scope(scope) all_in(scope_values: scope) end |
.where_secret(secret, client_uri) ⇒ Object
Filter to the client secret and the redirect uri
86 87 88 |
# File 'app/models/oauth2_provider/client.rb', line 86 def where_secret(secret, client_uri) where(secret: secret, uri: client_uri) end |
.where_uri(client_uri, redirect_uri) ⇒ Object
Filter to the client uri (internal identifier) and the redirect uri
81 82 83 |
# File 'app/models/oauth2_provider/client.rb', line 81 def where_uri(client_uri, redirect_uri) where(uri: client_uri, redirect_uri: redirect_uri) end |
Instance Method Details
#block! ⇒ Object
Block the client
35 36 37 38 39 40 |
# File 'app/models/oauth2_provider/client.rb', line 35 def block! self.blocked = Time.now self.save OauthToken.block_client!(self.uri) OauthAuthorization.block_client!(self.uri) end |
#blocked? ⇒ Boolean
Check if the status is or is not blocked
49 50 51 |
# File 'app/models/oauth2_provider/client.rb', line 49 def blocked? !self.blocked.nil? end |
#granted! ⇒ Object
Increase the counter of resource owners granting the access to the client
55 56 57 58 |
# File 'app/models/oauth2_provider/client.rb', line 55 def granted! self.granted_times += 1 self.save end |
#revoked! ⇒ Object
Increase the counter of resource owners revoking the access to the client
62 63 64 65 |
# File 'app/models/oauth2_provider/client.rb', line 62 def revoked! self.revoked_times += 1 self.save end |
#scope_pretty ⇒ Object
67 68 69 70 |
# File 'app/models/oauth2_provider/client.rb', line 67 def scope_pretty separator = Oauth2Provider.settings["scope_separator"] scope.join(separator) end |
#scope_values_pretty ⇒ Object
72 73 74 75 |
# File 'app/models/oauth2_provider/client.rb', line 72 def scope_values_pretty separator = Oauth2Provider.settings["scope_separator"] scope_values.join(separator) end |
#unblock! ⇒ Object
Unblock the client
43 44 45 46 |
# File 'app/models/oauth2_provider/client.rb', line 43 def unblock! self.blocked = nil self.save end |