Skip to content
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

UI: Add exchange of one-time token on application load #10066

Merged
merged 15 commits into from
Apr 1, 2021
Merged

Conversation

backspace
Copy link
Contributor

@backspace backspace commented Feb 22, 2021

This adds UI support for receiving the one-time token passed via query parameter, as in #10134
and related PRs, and exchanging it for its corresponding secret ID. When this works, it’s mostly
invisible, as seen here when used with nomad ui -authenticate, where the OTT is briefly onscreen:

authenticate

You can also see the amended message when authentication fails suggesting to -authenticate.

When it fails, it shows a whole-page error:

failed

Unfortunately, I was unable to produce the desired UX of having the OTT be erased from the URL
after processing, so I’m submitting this for review with that sad caveat. This will only be seen when
jumping directly with an identifier (nomad ui -authenticate jobname), as nomad ui -authenticate
forwards to /ui/?ott=… which then forwards to /ui/jobs after the exchange is complete, but it’s
undesirable regardless. I’ll continue trying to find a way to cleanly and reliably remove it.

leftover

The whole-page error currently has this minimal text:

Failed to exchange the one-time token.

This is an edge case where I can’t actually imagine what would produce it, but the error doesn’t
really help you if it does happen… I’m open to suggestions for something better!

@github-actions
Copy link

github-actions bot commented Feb 22, 2021

Ember Asset Size action

As of 412da49

Files that got Bigger 🚨:

File raw gzip
nomad-ui.js +1.95 kB +572 B
nomad-ui.css +290 B +42 B

Files that stayed the same size 🤷‍:

File raw gzip
vendor.js 0 B 0 B
vendor.css 0 B 0 B

@github-actions
Copy link

github-actions bot commented Feb 22, 2021

Ember Test Audit comparison

main 412da49 change
passes 1072 1074 +2
failures 0 0 0
flaky 0 0 0
duration 8m 31s 865ms 9m 00s 615ms +28s 750ms

@tgross
Copy link
Member

tgross commented Mar 10, 2021

@backspace just a heads up that #10134 has been merged.

@backspace
Copy link
Contributor Author

Thanks! Sadly I likely won’t be able to return to this until March 22, but hopefully things proceed smoothly then 😯

<h1 data-test-error-title class="title is-spaced">Token Exchange Error</h1>
<p data-test-error-message class="subtitle">
Failed to exchange the one-time token.
</p>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the existing no-leader-error pattern and created the ott-exchange-error that’s checked for here to display this custom message… maybe a more generic known error type with custom title and message would be useful eventually 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Errors and notifications I think are high on the "to refactor" list.

@backspace backspace marked this pull request as ready for review March 31, 2021 03:50
Copy link
Contributor

@DingoEatingFuzz DingoEatingFuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Works as advertised!

I agree that it would be nice if the query param always got deleted, but I think your choice to ship this as is and follow up with that improvement is the right call.

Everything here is looking good aside from the couple br elements I'd like to avoid introducing. Aside from that, comments are commentary and weak suggestions.

ui/app/routes/application.js Show resolved Hide resolved
const token = yield TokenAdapter.exchangeOneTimeToken(oneTimeToken);
this.secret = token.secret;
})
exchangeOneTimeToken;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ totally random thoughts that you don't have to take seriously

Hm, even though it's consistent to the file to use an EC task here, looking at this with fresh eyes it seems like a simple promise would suffice? We aren't doing any fancy chaining or error control flow. Idk.

Copy link
Contributor Author

@backspace backspace Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it seriously in fa06c5e, it makes sense to remove the needless wrapping, thank you!


.terminal {
background: $grey-lighter;
border-radius: 2px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use $radius here.

Copy link
Contributor Author

@backspace backspace Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ffc9593, thanks 😀

ui/app/styles/components/empty-message.scss Show resolved Hide resolved
<h1 data-test-error-title class="title is-spaced">Token Exchange Error</h1>
<p data-test-error-message class="subtitle">
Failed to exchange the one-time token.
</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Errors and notifications I think are high on the "to refactor" list.

@@ -17,6 +17,12 @@
requisite
{{/if}}
permission to view this.
<br>
<br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, is this the first instance of two paragraphs of text in the UI? I couldn't find any prior art for this type of spacing.

What do you think about changing empty-message-body to being a div and then making each line a p and then creating this paragraph spacing with margins instead?

Something like this in the .empty-message-body selector:

p:not(:last-child) {
  margin-bottom: 0.5rem; // idk how much spacing this should actually be, somewhere between 0.5 and 1.
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did find this two-paragraph empty message, though it’s slightly different in that the second paragraph is a button. In 412da49 I added this within .empty-message-body:

    &:not(:last-child) {
      margin-bottom: 1rem;
    }

and removed the unsightly <br>s, thanks for the push there. Here are screenshots of these two two-paragraph messages, does it seem suitable to you?

double-p-existing

double-p-terminal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

exchangeOneTimeToken = this.get('token.exchangeOneTimeToken')
.perform(transition.to.queryParams.ott)
.catch(() => {
this.controllerFor('application').set('error', new OTTExchangeError());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally this error casting would happen in the data layer. Presumably in the token adapter.

Not a big deal though if that ends up being more trouble than it's worth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was easy enough, makes sense, done in d5e2e5d, thank you!

Copy link
Contributor

@DingoEatingFuzz DingoEatingFuzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: Nice work!

@backspace backspace merged commit 7af5afb into main Apr 1, 2021
@backspace backspace deleted the f-ui/ott branch April 1, 2021 18:21
backspace added a commit that referenced this pull request Apr 13, 2021
This followup to #10066 adds a step to clear the one-time token
from the URL after the application has loaded. The delay is
required for it to actually clear, but only when the OTT is present
to avoid slowing down the entire test suite.
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants