-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3938 from 3scale/THREESCALE-11439-signed-cms-token
THREESCALE-11439: Sign the CMS token
- Loading branch information
Showing
11 changed files
with
92 additions
and
18 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
app/controllers/provider/admin/cms/visit_portal_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class Provider::Admin::CMS::VisitPortalController < Provider::Admin::CMS::BaseController | ||
# Encrypt the CMS token under a temporary SSO token and redirect to the Developer Portal | ||
def with_token | ||
cms_token = current_account.settings.cms_token! | ||
expires_at = Time.now.utc.round + 1.minute | ||
signature = CMS::Signature.generate(cms_token, expires_at) | ||
|
||
redirect_to access_code_url( | ||
host: current_account.external_domain, | ||
signature:, | ||
expires_at: expires_at.to_i, | ||
access_code: current_account.site_access_code, | ||
return_to:, | ||
cms: cms_mode) | ||
end | ||
|
||
private | ||
|
||
def return_to | ||
params.permit(:return_to)[:return_to] | ||
end | ||
|
||
def cms_mode | ||
session[:cms] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module CMS | ||
class Signature | ||
def self.generate(token, expires_at) | ||
verifier = Rails.application.message_verifier(:cms_token) | ||
signing_options = { purpose: :cms_edit_mode, expires_at: expires_at.utc.floor } | ||
verifier.generate(token.b, **signing_options).split("--").last | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,6 +354,7 @@ | |
end | ||
|
||
end | ||
get 'visit_portal' => 'visit_portal#with_token' | ||
end | ||
|
||
namespace :user do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
features/step_definitions/developer_portal/cms_toolbar_steps.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters