Newer
Older
Raphael Sofaer
a validé
class AuthorizationsController < ApplicationController
include OAuth2::Provider::Rack::AuthorizationCodesSupport
before_filter :authenticate_user!, :except => :token
before_filter :block_invalid_authorization_code_requests, :except => [:token, :index, :destroy]
skip_before_filter :verify_authenticity_token, :only => :token
Raphael Sofaer
a validé
def new
@requested_scopes = params["scope"].split(',')
Raphael Sofaer
a validé
@client = oauth2_authorization_request.client
render :layout => "popup" if params[:popup]
Raphael Sofaer
a validé
end
def create
Raphael Sofaer
a validé
grant_authorization_code(current_user)
else
deny_authorization_code
end
end
if(params[:type] == 'client_associate' && params[:manifest_url])
client = OAuth2::Provider.client_class.create_from_manifest!(params[:manifest_url])
render :json => {:client_id => client.oauth_identifier,
:client_secret => client.oauth_secret,
:expires_in => 0,
:flows_supported => "",
}
else
render :text => "bad request", :status => 403
end
end
Ilya Zhitomirskiy
a validé
def index
@authorizations = current_user.authorizations
@applications = current_user.applications
end
def destroy
## ID is actually the id of the client
auth = current_user.authorizations.where(:client_id => params[:id]).first
auth.revoke
redirect_to authorizations_path
end
Raphael Sofaer
a validé
end
OAuth2::Provider.client_class.instance_eval do
def self.create_from_manifest! manifest_url
manifest = JSON.parse(RestClient.get(manifest_url).body)
create!(manifest)
end
end