diff options
author | Valery Sizov <vsv2711@gmail.com> | 2014-12-19 17:15:29 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2014-12-24 16:38:07 +0300 |
commit | e41dadcb33fda44ee274daa673bd933e13aa90eb (patch) | |
tree | ef0dc6ecea0020fe1ce8598342bcbf7e620984fe /app/controllers/oauth/authorizations_controller.rb | |
parent | 5cf2bd4c997d84e9a02d722d6ba870c24b06cc0f (diff) |
Doorkeeper integration
Diffstat (limited to 'app/controllers/oauth/authorizations_controller.rb')
-rw-r--r-- | app/controllers/oauth/authorizations_controller.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/app/controllers/oauth/authorizations_controller.rb b/app/controllers/oauth/authorizations_controller.rb new file mode 100644 index 00000000000..c46707e2c77 --- /dev/null +++ b/app/controllers/oauth/authorizations_controller.rb @@ -0,0 +1,57 @@ +class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController + before_filter :authenticate_resource_owner! + layout "profile" + + def new + if pre_auth.authorizable? + if skip_authorization? || matching_token? + auth = authorization.authorize + redirect_to auth.redirect_uri + else + render "doorkeeper/authorizations/new" + end + else + render "doorkeeper/authorizations/error" + end + end + + # TODO: Handle raise invalid authorization + def create + redirect_or_render authorization.authorize + end + + def destroy + redirect_or_render authorization.deny + end + + private + + def matching_token? + Doorkeeper::AccessToken.matching_token_for pre_auth.client, + current_resource_owner.id, + pre_auth.scopes + end + + def redirect_or_render(auth) + if auth.redirectable? + redirect_to auth.redirect_uri + else + render json: auth.body, status: auth.status + end + end + + def pre_auth + @pre_auth ||= Doorkeeper::OAuth::PreAuthorization.new(Doorkeeper.configuration, + server.client_via_uid, + params) + end + + def authorization + @authorization ||= strategy.request + end + + def strategy + @strategy ||= server.authorization_request pre_auth.response_type + end +end + |