-
Notifications
You must be signed in to change notification settings - Fork 5
Spike to move editor into editor-api #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
zetter-rpf
wants to merge
18
commits into
main
Choose a base branch
from
editor-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5db78ac
Serve Code Editor pages from editor-api on the editor host
zetter-rpf e8dd580
Stop CORP header depending on how origins are read from ENV
zetter-rpf 0327b47
Render the Code Editor home page on the server
zetter-rpf de5bc02
Show the global navigation on Code Editor pages
zetter-rpf f88c2fd
Give the Code Editor home page its secondary navigation
zetter-rpf d61ad7c
Add the footer to Code Editor pages
zetter-rpf 37ed492
Keep en-US pages working once UploadJob has loaded
zetter-rpf 1f02da6
Document the Code Editor migration in the engine
zetter-rpf db5b241
Point agent instructions at the Code Editor migration plan
zetter-rpf a3f78f8
Log in to the Code Editor with its own Hydra client
zetter-rpf cbf0eba
Return users to the page they logged in from
zetter-rpf 2287c6f
Give the editor web component the signed-in user's token
zetter-rpf f905240
Keep the editor signed in without reloading the page
zetter-rpf dbafd9f
Record how Code Editor auth was built in the migration plan
zetter-rpf 6cd002e
Stop the editor pages loading a JavaScript module that is absent
zetter-rpf db69ae4
Serve the Code Editor project page from editor-api
zetter-rpf 9375227
Let people list, create, rename and delete their projects
zetter-rpf ceda7c5
Record the project pages in the migration plan
zetter-rpf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class SilentRenewController < ApplicationController | ||
| layout false | ||
|
|
||
| def start | ||
| return head :forbidden unless current_user | ||
|
|
||
| session[:silent_renew_state] = SecureRandom.hex(24) | ||
| session[:silent_renew_verifier] = SecureRandom.hex(64) | ||
|
|
||
| redirect_to authorize_url, allow_other_host: true | ||
| end | ||
|
|
||
| def callback | ||
| state = session.delete(:silent_renew_state) | ||
| verifier = session.delete(:silent_renew_verifier) | ||
|
|
||
| @renewed = params[:code].present? && matching_state?(state) && renew(params[:code], verifier) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def matching_state?(state) | ||
| state.present? && ActiveSupport::SecurityUtils.secure_compare(params[:state].to_s, state) | ||
| end | ||
|
|
||
| def renew(code, verifier) | ||
| token = EditorHydraClient.oauth_client.auth_code.get_token( | ||
| code, redirect_uri: silent_renew_url, code_verifier: verifier | ||
| ) | ||
|
|
||
| self.current_user = User.from_id_token(token.params['id_token'], token.token) | ||
| session[:oauth_expires_at] = token.expires_at | ||
| true | ||
| rescue OAuth2::Error => e | ||
| Rails.logger.info { "Silent renew failed: #{e.message}" } | ||
| false | ||
| end | ||
|
|
||
| def authorize_url | ||
| query = { | ||
| client_id: EditorHydraClient.client_id, | ||
| redirect_uri: silent_renew_url, | ||
| response_type: 'code', | ||
| scope: EditorHydraClient::SCOPE, | ||
| state: session[:silent_renew_state], | ||
| prompt: 'none', | ||
| code_challenge: code_challenge, | ||
| code_challenge_method: 'S256' | ||
| } | ||
|
|
||
| "#{EditorHydraClient.authorize_url}?#{query.to_query}" | ||
| end | ||
|
|
||
| def code_challenge | ||
| Base64.urlsafe_encode64(Digest::SHA2.digest(session[:silent_renew_verifier]), padding: false) | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,21 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <title>Silent renew</title> | ||
| <% if @renewed %> | ||
| <%= render EditorApp::AuthTokenComponent.new(user: current_user, expires_at: session[:oauth_expires_at]) %> | ||
| <% end %> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| window.parent.postMessage( | ||
| { | ||
| type: "editor-app:session-renewal", | ||
| renewed: <%= @renewed ? 'true' : 'false' %>, | ||
| expiresAt: <%= raw ERB::Util.json_escape(session[:oauth_expires_at].to_json) %> | ||
| }, | ||
| window.origin | ||
| ); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these should be here rather than in the EditorApp