Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Enable polymoprhic resource owners for OAuth Access Tokens (#11350)
Damian Legawiec8c3b7ea218a1
diff --git a/api/config/initializers/doorkeeper.rb b/api/config/initializers/doorkeeper.rbindex 013613077b..b16b7020f7 100644--- a/api/config/initializers/doorkeeper.rb+++ b/api/config/initializers/doorkeeper.rb@@ -4,9 +4,12 @@ Doorkeeper.configure doapi_onlybase_controller 'ActionController::API'+ # FIXME: we should only skip this for Storefront API until v5+ # we should not skip this for Platform APIskip_client_authentication_for_password_grant { true } if defined?(skip_client_authentication_for_password_grant)resource_owner_authenticator { current_spree_user }+ use_polymorphic_resource_ownerresource_owner_from_credentials douser = Spree.user_class.find_for_database_authentication(email: params[:username])diff --git a/api/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb b/api/db/migrate/20210919183228_enable_polymorphic_resource_owner.rbnew file mode 100644index 0000000000..081b32da70--- /dev/null+++ b/api/db/migrate/20210919183228_enable_polymorphic_resource_owner.rb@@ -0,0 +1,21 @@+class EnablePolymorphicResourceOwner < ActiveRecord::Migration[5.2]+ def change+ add_column :spree_oauth_access_tokens, :resource_owner_type, :string+ add_column :spree_oauth_access_grants, :resource_owner_type, :string+ change_column_null :spree_oauth_access_grants, :resource_owner_type, false++ add_index :spree_oauth_access_tokens,+ [:resource_owner_id, :resource_owner_type],+ name: 'polymorphic_owner_oauth_access_tokens'++ add_index :spree_oauth_access_grants,+ [:resource_owner_id, :resource_owner_type],+ name: 'polymorphic_owner_oauth_access_grants'++ Spree::OauthAccessToken.reset_column_information+ Spree::OauthAccessToken.update_all(resource_owner_type: Spree.user_class)++ Spree::OauthAccessGrant.reset_column_information+ Spree::OauthAccessGrant.update_all(resource_owner_type: Spree.user_class)+ end+enddiff --git a/api/spec/requests/spree/oauth/token_spec.rb b/api/spec/requests/spree/oauth/token_spec.rbindex 62f2da8c03..b92e793c10 100644--- a/api/spec/requests/spree/oauth/token_spec.rb+++ b/api/spec/requests/spree/oauth/token_spec.rb@@ -37,6 +37,12 @@ describe 'Spree OAuth', type: :request docontext 'when the user is confirmed' dolet(:active_value) { true }+ let(:token) { Spree::OauthAccessToken.active_for(user).last }++ it 'creates new token' do+ expect(token.resource_owner_id).to eq(user.id)+ expect(token.resource_owner_type).to eq('Spree::LegacyUser')+ endit 'returns new token' doexpect(response.status).to eq(200)