Class: Rack::OAuth2::Server::Client

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rack/oauth2/models/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.lookup(field) ⇒ Object

Lookup client by ID, display name or URL.



61
62
63
# File 'lib/rack/oauth2/models/client.rb', line 61

def self.lookup(field)
  find_by_id(field) || find_by_code(field) || find_by_display_name(field) || find_by_link(field)
end

Instance Method Details

#assign_code_and_secretObject

Create a new client. Client provides the following properties: # :display_name – Name to show (e.g. UberClient) # :link – Link to client Web site (e.g. uberclient.dot) # :image_url – URL of image to show alongside display name # :redirect_uri – Registered redirect URI. # :scope – List of names the client is allowed to request. # :notes – Free form text.

This method does not validate any of these fields, in fact, you’re not required to set them, use them, or use them as suggested. Using them as suggested would result in better user experience. Don’t ask how we learned that. def self.create(args)

unless args[:redirect_uri].blank?
  redirect_uri = Server::Utils.parse_redirect_uri(args.delete(:redirect_uri)).to_s
end

scope = Server::Utils.normalize_scope(args[:scope])
args.merge!({:redirect_uri => redirect_uri})

if args[:id] && args[:secret]
  args[:code] = args.delete(:id)
  super(args)
else
  args[:secret] = Server.secure_random
  super(args)
end

end



51
52
53
54
# File 'lib/rack/oauth2/models/client.rb', line 51

def assign_code_and_secret
  self.code = Server.secure_random[0,20]
  self.secret = Server.secure_random
end

#redirect_url=(url) ⇒ Object



56
57
58
# File 'lib/rack/oauth2/models/client.rb', line 56

def redirect_url=(url)
  self[:redirect_uri] = Server::Utils.parse_redirect_uri(url).to_s
end

#revoke!Object

Revoke all authorization requests, access grants and access tokens for this client. Ward off the evil.



72
73
74
75
76
77
78
79
# File 'lib/rack/oauth2/models/client.rb', line 72

def revoke!
  revoked_at = Time.now
  update_attribute(:revoked, revoked_at)
  # can we use the association here
  AuthRequest.update_all(:revoked=>revoked_at, :client_id=>id)
  AccessGrant.update_all(:revoked=>revoked_at, :client_id=>id)
  AccessToken.update_all(:revoked=>revoked_at, :client_id=>id)
end