1 require "oauth/controllers/provider_controller"
3 class OauthController < ApplicationController
4 include OAuth::Controllers::ProviderController
14 def user_authorizes_token?
17 @token.client_application.permissions.each do |pref|
19 @token.write_attribute(pref, true)
22 @token.write_attribute(pref, false)
30 @token = current_user.oauth_tokens.find_by_token params[:token]
33 flash[:notice] = t("oauth.revoke.flash", :application => @token.client_application.name)
35 redirect_to oauth_clients_url(:display_name => @token.user.display_name)
41 if @token.invalidated?
42 @message = t "oauth.oauthorize_failure.invalid"
43 render :action => "authorize_failure"
45 if user_authorizes_token?
46 @token.authorize!(current_user)
47 callback_url = if @token.oauth10?
48 params[:oauth_callback] || @token.client_application.callback_url
50 @token.oob? ? @token.client_application.callback_url : @token.callback_url
52 @redirect_url = URI.parse(callback_url) unless callback_url.blank?
54 if @redirect_url.to_s.blank?
55 render :action => "authorize_success"
57 @redirect_url.query = if @redirect_url.query.blank?
58 "oauth_token=#{@token.token}"
61 "&oauth_token=#{@token.token}"
64 unless @token.oauth10?
65 @redirect_url.query += "&oauth_verifier=#{@token.verifier}"
68 redirect_to @redirect_url.to_s
72 @message = t("oauth.oauthorize_failure.denied", :app_name => @token.client_application.name)
73 render :action => "authorize_failure"