From 5726b37fb9783e672b3cc351fbf8e961e1a69fda Mon Sep 17 00:00:00 2001 From: Jonne Hass Date: Sun, 11 Dec 2011 01:37:15 +0100 Subject: [PATCH] diaspora connect: fix edge case where pod lost the client information --- app/controllers/authorizations_controller.rb | 16 +++++++++++++++- features/oauth.feature | 1 - 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/authorizations_controller.rb b/app/controllers/authorizations_controller.rb index 97ac6e4b1..d66bf54af 100644 --- a/app/controllers/authorizations_controller.rb +++ b/app/controllers/authorizations_controller.rb @@ -4,7 +4,7 @@ require File.join(Rails.root, "app", "models", "oauth2_provider_models_activerec 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] + before_filter :redirect_or_block_invalid_authorization_code_requests, :except => [:token, :index, :destroy] skip_before_filter :verify_authenticity_token, :only => :token @@ -101,6 +101,8 @@ class AuthorizationsController < ApplicationController redirect_to authorizations_path end + private + # @param [String] enc_signed_string A Base64 encoded string with app_url;pod_url;time;nonce # @param [String] sig A Base64 encoded signature of the decoded signed_string with public_key. # @param [OpenSSL::PKey::RSA] public_key The application's public key to verify sig with. @@ -131,4 +133,16 @@ class AuthorizationsController < ApplicationController def valid_nonce?(nonce) !OAuth2::Provider.client_class.exists?(:nonce => nonce) end + + def redirect_or_block_invalid_authorization_code_requests + begin + block_invalid_authorization_code_requests + rescue OAuth2::Provider::Rack::InvalidRequest => e + if e.message == "client_id is invalid" + redirect_to params[:redirect_uri]+"&error=invalid_client" + else + raise + end + end + end end diff --git a/features/oauth.feature b/features/oauth.feature index 07218f9d4..e572e27c0 100644 --- a/features/oauth.feature +++ b/features/oauth.feature @@ -89,7 +89,6 @@ Feature: oauth Then I visit "/account?id=1" on Chubbies Then I should see "Token invalid" - @wip Scenario: Re-registering a client if the client recognizes the diaspora pod but the diaspora pod has since been reset Given Chubbies is registered on my pod And I remove all traces of Chubbies on the pod