1 class OauthController < ApplicationController
2 include OAuth::Controllers::ProviderController
4 # The ProviderController will call login_required for any action that needs
5 # a login, but we want to check authorization on every action.
6 authorize_resource :class => false
8 before_action :require_oauth_10a_support
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|
32 if params[pref].to_i.nonzero?
33 @token.write_attribute(pref, true)
36 @token.write_attribute(pref, false)
44 override_content_security_policy_directives(:form_action => []) if Settings.csp_enforce || Settings.key?(: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, :allow_other_host => true
75 @message = t("oauth.authorize_failure.denied", :app_name => @token.client_application.name)
76 render :action => "authorize_failure"