OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Do it!
Jan Sandbrink77c203f9b75d
diff --git a/modules/openid_connect/app/services/openid_connect/user_tokens/exchange_service.rb b/modules/openid_connect/app/services/openid_connect/user_tokens/exchange_service.rbindex 36891712bf7..b32c8b10aa6 100644--- a/modules/openid_connect/app/services/openid_connect/user_tokens/exchange_service.rb+++ b/modules/openid_connect/app/services/openid_connect/user_tokens/exchange_service.rb@@ -32,6 +32,7 @@ module OpenIDConnectmodule UserTokensclass ExchangeServiceinclude Dry::Monads[:result]+ include Dry::Monads::Do.for(:call)class Disabledclass << self@@ -50,19 +51,17 @@ module OpenIDConnectdef call(audience)return Failure("Provider does not support token exchange") unless supported?- FetchService.new(user: @user, token_exchange: Disabled)- .access_token_for(audience: UserToken::IDP_AUDIENCE)- .bind do |idp_token|- exchange_token_request(idp_token, audience).bind do |json|- access_token = json["access_token"]- refresh_token = json["refresh_token"]- break Failure("Token exchange response invalid") if access_token.blank?+ idp_token = yield FetchService.new(user: @user, token_exchange: Disabled)+ .access_token_for(audience: UserToken::IDP_AUDIENCE)- token = store_exchanged_token(audience:, access_token:, refresh_token:)+ json = yield exchange_token_request(idp_token, audience)- Success(token)- end- end+ access_token = json["access_token"]+ refresh_token = json["refresh_token"]+ return Failure("Token exchange response invalid") if access_token.blank?++ token = store_exchanged_token(audience:, access_token:, refresh_token:)+ Success(token)enddef supported?diff --git a/modules/openid_connect/app/services/openid_connect/user_tokens/fetch_service.rb b/modules/openid_connect/app/services/openid_connect/user_tokens/fetch_service.rbindex 6ca2ff4a951..2baa1a62ea0 100644--- a/modules/openid_connect/app/services/openid_connect/user_tokens/fetch_service.rb+++ b/modules/openid_connect/app/services/openid_connect/user_tokens/fetch_service.rb@@ -36,6 +36,7 @@ module OpenIDConnect# client_id at an identity provider that OpenProject and the application have in common.class FetchServiceinclude Dry::Monads[:result]+ include Dry::Monads::Do.for(:access_token_for, :refreshed_access_token_for)def initialize(user:,jwt_parser: JwtParser.new(verify_audience: false, verify_expiration: false),@@ -59,16 +60,10 @@ module OpenIDConnect# A token exchange is attempted, if the provider supports OAuth 2.0 Token Exchange and a token# for the target audience either can't be found or it has expired, but has no available refresh token.def access_token_for(audience:)- token = token_with_audience(audience)- token = token.bind do |t|- if expired?(t.access_token)- @token_refresh.call(t)- else- Success(t)- end- end+ token = yield token_with_audience(audience)+ token = yield @token_refresh.call(token) if expired?(token.access_token)- token.fmap(&:access_token)+ Success(token.access_token)end##@@ -82,9 +77,9 @@ module OpenIDConnect# A token exchange is attempted, if the provider supports OAuth 2.0 Token Exchange and a token# for the target audience either can't be found or it has expired, but has no available refresh token.def refreshed_access_token_for(audience:)- token_with_audience(audience)- .bind { |t| @token_refresh.call(t) }- .fmap(&:access_token)+ token = yield token_with_audience(audience)+ token = yield @token_refresh.call(token)+ Success(token.access_token)endprivatediff --git a/modules/openid_connect/app/services/openid_connect/user_tokens/refresh_service.rb b/modules/openid_connect/app/services/openid_connect/user_tokens/refresh_service.rbindex f8658d89205..8d73536d6d6 100644--- a/modules/openid_connect/app/services/openid_connect/user_tokens/refresh_service.rb+++ b/modules/openid_connect/app/services/openid_connect/user_tokens/refresh_service.rb@@ -32,6 +32,7 @@ module OpenIDConnectmodule UserTokensclass RefreshServiceinclude Dry::Monads[:result]+ include Dry::Monads::Do.for(:call)def initialize(user:, token_exchange:)@user = user@@ -43,15 +44,15 @@ module OpenIDConnectreturn exchange_instead_of_refresh(token)end- refresh_token_request(token.refresh_token).bind do |json|- access_token = json["access_token"]- refresh_token = json["refresh_token"]- break Failure("Refresh token response invalid") if access_token.blank?+ json = yield refresh_token_request(token.refresh_token)- token.update!(access_token:, refresh_token:)+ access_token = json["access_token"]+ refresh_token = json["refresh_token"]+ return Failure("Refresh token response invalid") if access_token.blank?- Success(token)- end+ token.update!(access_token:, refresh_token:)++ Success(token)endprivate