class Rack::OAuth2::Server::Admin

Public Class Methods

mount(path = "/oauth/admin") click to toggle source

Returns Rack handle that mounts Admin on the specified path, and forwards all other requests back to the application.

@param [String, nil] path The path to mount on, defaults to /oauth/admin @return [Object] Rack module

@example To include Web admin in Rails 2.x app:

config.middleware.use Rack::OAuth2::Server::Admin.mount
# File lib/rack/oauth2/server/admin.rb, line 57
def mount(path = "/oauth/admin")
  mount = Class.new(Mount)
  mount.mount Admin, path
  mount
end

Public Instance Methods

client_as_json(client, with_stats = false) click to toggle source
# File lib/rack/oauth2/server/admin.rb, line 246
def client_as_json(client, with_stats = false)
  { "id"=>client.id.to_s, "secret"=>client.secret, :redirectUri=>client.redirect_uri,
    :displayName=>client.display_name, :link=>client.link, :imageUrl=>client.image_url,
    :notes=>client.notes, :scope=>client.scope,
    :url=>"#{request.script_name}/api/client/#{client.id}",
    :revoke=>"#{request.script_name}/api/client/#{client.id}/revoke",
    :history=>"#{request.script_name}/api/client/#{client.id}/history",
    :created=>client.created_at, :revoked=>client.revoked }
end
token_as_json(token) click to toggle source
# File lib/rack/oauth2/server/admin.rb, line 256
def token_as_json(token)
  { :token=>token.token, :identity=>token.identity, :scope=>token.scope, :created=>token.created_at,
    :expired=>token.expires_at, :revoked=>token.revoked,
    :link=>settings.template_url && settings.template_url.gsub("{id}", token.identity),
    :last_access=>token.last_access,
    :revoke=>"#{request.script_name}/api/token/#{token.token}/revoke" }
end
validate_params(params) click to toggle source
# File lib/rack/oauth2/server/admin.rb, line 226
def validate_params(params)
  display_name = params[:displayName].to_s.strip
  halt 400, "Missing display name" if display_name.empty?
  link = URI.parse(params[:link].to_s.strip).normalize rescue nil
  halt 400, "Link is not a URL (must be http://....)" unless link
  halt 400, "Link must be an absolute URL with HTTP/S scheme" unless link.absolute? && %{http https}.include?(link.scheme)
  redirect_uri = URI.parse(params[:redirectUri].to_s.strip).normalize rescue nil
  halt 400, "Redirect URL is not a URL (must be http://....)" unless redirect_uri
  halt 400, "Redirect URL must be an absolute URL with HTTP/S scheme" unless
    redirect_uri.absolute? && %{http https}.include?(redirect_uri.scheme)
  unless params[:imageUrl].nil? || params[:imageUrl].to_s.empty?
    image_url = URI.parse(params[:imageUrl].to_s.strip).normalize rescue nil
    halt 400, "Image URL must be an absolute URL with HTTP/S scheme" unless
      image_url.absolute? && %{http https}.include?(image_url.scheme)
  end
  scope = Server::Utils.normalize_scope(params[:scope])
  { :display_name=>display_name, :link=>link.to_s, :image_url=>image_url.to_s,
    :redirect_uri=>redirect_uri.to_s, :scope=>scope, :notes=>params[:notes] }
end