-
Notifications
You must be signed in to change notification settings - Fork 62
Serve console index at /settings/*, /device/verify, /device/success
#1324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3b9e36
serve console index at /settings/*
david-crespo 6db573c
use full helper for /device/verify too
david-crespo 92b870a
also do /device/success
david-crespo 5c33d76
first pass at always including current URI in login_url
david-crespo 1ef808a
improve code slightly, add big comment
david-crespo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| //! are for requesting access tokens that will be managed and used by | ||
| //! the client to make other API requests. | ||
|
|
||
| use super::console_api::{get_login_url, serve_console_index}; | ||
| use super::console_api::console_index_or_login_redirect; | ||
| use super::views::{DeviceAccessTokenGrant, DeviceAuthResponse}; | ||
| use crate::context::OpContext; | ||
| use crate::db::model::DeviceAccessToken; | ||
|
|
@@ -21,7 +21,6 @@ use http::{header, Response, StatusCode}; | |
| use hyper::Body; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_urlencoded; | ||
| use std::sync::Arc; | ||
| use uuid::Uuid; | ||
|
|
||
|
|
@@ -126,26 +125,20 @@ pub struct DeviceAuthVerify { | |
| }] | ||
| pub async fn device_auth_verify( | ||
| rqctx: Arc<RequestContext<Arc<ServerContext>>>, | ||
| params: Query<DeviceAuthVerify>, | ||
| _params: Query<DeviceAuthVerify>, | ||
| ) -> Result<Response<Body>, HttpError> { | ||
| // If the user is authenticated, serve the console verification page. | ||
| if let Ok(opctx) = OpContext::for_external_api(&rqctx).await { | ||
| if opctx.authn.actor().is_some() { | ||
| return serve_console_index(rqctx.context()).await; | ||
| } | ||
| } | ||
| console_index_or_login_redirect(rqctx).await | ||
| } | ||
|
|
||
| // Otherwise, redirect for authentication. | ||
| let params = params.into_inner(); | ||
| let state_params = serde_urlencoded::to_string(serde_json::json!({ | ||
| "user_code": params.user_code | ||
| })) | ||
| .map_err(|e| HttpError::for_internal_error(e.to_string()))?; | ||
| let state = Some(format!("/device/verify?{}", state_params)); | ||
| Ok(Response::builder() | ||
| .status(StatusCode::FOUND) | ||
| .header(http::header::LOCATION, get_login_url(state)) | ||
| .body("".into())?) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plotnick I just noticed my version does not automatically put the current path + query in |
||
| #[endpoint { | ||
| method = GET, | ||
| path = "/device/success", | ||
| unpublished = true, | ||
| }] | ||
| pub async fn device_auth_success( | ||
| rqctx: Arc<RequestContext<Arc<ServerContext>>>, | ||
| ) -> Result<Response<Body>, HttpError> { | ||
| console_index_or_login_redirect(rqctx).await | ||
| } | ||
|
|
||
| /// Confirm an OAuth 2.0 Device Authorization Grant | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
a) is this the logic we want
b) in tests this leaves off the domain, but will it always do that? not sure if we care either way
c) assuming this is what we want, is this really the least ugly way to get it
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.
a) I think so
b) Technically,
Locationredirects should use absolute URIs, but I'm not sure it actually matters much in the modern world.c) Seems like, since we can't depend on any particular set of parameters being passed into this function.
Uh oh!
There was an error while loading. Please reload this page.
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.
Eventually this will get a bit fancier (well, the fanciness will probably live in
get_login_url) because I think the value of the state param is supposed to be hashed together with some kind of token so it can mitigate request forgery.