1 require "oauth/controllers/provider_controller"
3 class OauthController < ApplicationController
4 include OAuth::Controllers::ProviderController
6 # The ProviderController will call login_required for any action that needs
7 # a login, but we want to check authorization on every action.
8 authorize_resource :class => false
13 @token = current_user.oauth_tokens.find_by :token => params[:token]
16 flash[:notice] = t(".flash", :application => @token.client_application.name)
18 redirect_to oauth_clients_url(:display_name => @token.user.display_name)
28 def user_authorizes_token?
31 @token.client_application.permissions.each do |pref|
33 @token.write_attribute(pref, true)
36 @token.write_attribute(pref, false)
44 override_content_security_policy_directives(:form_action => []) if CSP_ENFORCE || defined?(CSP_REPORT_URL)
46 if @token.invalidated?
47 @message = t "oauth.authorize_failure.invalid"
48 render :action => "authorize_failure"
50 if user_authorizes_token?
51 @token.authorize!(current_user)
52 callback_url = if @token.oauth10?
53 params[:oauth_callback] || @token.client_application.callback_url
55 @token.oob? ? @token.client_application.callback_url : @token.callback_url
57 @redirect_url = URI.parse(callback_url) if callback_url.present?
59 if @redirect_url.to_s.blank?
60 render :action => "authorize_success"
62 @redirect_url.query = if @redirect_url.query.blank?
63 "oauth_token=#{@token.token}"
66 "&oauth_token=#{@token.token}"
69 @redirect_url.query += "&oauth_verifier=#{@token.verifier}" unless @token.oauth10?
71 redirect_to @redirect_url.to_s
75 @message = t("oauth.authorize_failure.denied", :app_name => @token.client_application.name)
76 render :action => "authorize_failure"