diff --git a/app/controllers/authorizations_controller.rb b/app/controllers/authorizations_controller.rb index c8e5bb856..97ac6e4b1 100644 --- a/app/controllers/authorizations_controller.rb +++ b/app/controllers/authorizations_controller.rb @@ -69,9 +69,8 @@ class AuthorizationsController < ApplicationController render :text => "Domain (#{manifest["application_base_url"]}) currently not authorized for Diaspora OAuth", :status => 403 else - client = OAuth2::Provider.client_class.create_or_reset_from_manifest!(manifest, public_key) + client = OAuth2::Provider.client_class.find_or_create_from_manifest!(manifest, public_key) - debugger json = {:client_id => client.oauth_identifier, :client_secret => client.oauth_secret, :expires_in => 0, diff --git a/app/models/oauth2_provider_models_activerecord_client.rb b/app/models/oauth2_provider_models_activerecord_client.rb index 92b6ddff1..5e9253884 100644 --- a/app/models/oauth2_provider_models_activerecord_client.rb +++ b/app/models/oauth2_provider_models_activerecord_client.rb @@ -1,19 +1,12 @@ -class OAuth2::Provider::Models::ActiveRecord::Client - def self.create_or_reset_from_manifest!(manifest, pub_key) - if obj = find_by_name(manifest['name']) - obj.oauth_identifier = OAuth2::Provider::Random.base62(16) - obj.oauth_secret = OAuth2::Provider::Random.base62(32) - obj.save! - obj - else - self.create!( - :name => manifest["name"], - :permissions_overview => manifest["permissions_overview"], - :description => manifest["description"], - :application_base_url => manifest["application_base_url"], - :icon_url => manifest["icon_url"], - :public_key => pub_key.export - ) - end +class OAuth2::Provider::Models::ActiveRecord::Client + def self.find_or_create_from_manifest!(manifest, pub_key) + find_by_name(manifest['name']) || self.create!( + :name => manifest["name"], + :permissions_overview => manifest["permissions_overview"], + :description => manifest["description"], + :application_base_url => manifest["application_base_url"], + :icon_url => manifest["icon_url"], + :public_key => pub_key.export + ) end end diff --git a/features/oauth.feature b/features/oauth.feature index 12adecd2b..c04a22bdd 100644 --- a/features/oauth.feature +++ b/features/oauth.feature @@ -85,6 +85,7 @@ 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 diff --git a/features/step_definitions/oauth_steps.rb b/features/step_definitions/oauth_steps.rb index f58599e17..6d5e94e62 100644 --- a/features/step_definitions/oauth_steps.rb +++ b/features/step_definitions/oauth_steps.rb @@ -11,7 +11,7 @@ Given /^Chubbies is registered on my pod$/ do public_key = OpenSSL::PKey::RSA.new(packaged_manifest['public_key']) manifest = JWT.decode(packaged_manifest['jwt'], public_key) - client = OAuth2::Provider.client_class.create_or_reset_from_manifest!(manifest, public_key) + client = OAuth2::Provider.client_class.find_or_create_from_manifest!(manifest, public_key) params = {:client_id => client.oauth_identifier, :client_secret => client.oauth_secret, :host => "localhost:9887"}