Skip to content

nexus: Update device_auth endpoint to use correct scheme (http/https) in response. #1601

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 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions nexus/db-model/src/device_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ pub struct DeviceAuthRequest {

impl DeviceAuthRequest {
// We need the host to construct absolute verification URIs.
pub fn into_response(self, host: &str) -> views::DeviceAuthResponse {
pub fn into_response(
self,
tls: bool,
host: &str,
) -> views::DeviceAuthResponse {
let scheme = if tls { "https" } else { "http" };
views::DeviceAuthResponse {
// TODO-security: use HTTPS
verification_uri: format!("http://{}/device/verify", host),
verification_uri: format!("{scheme}://{host}/device/verify"),
verification_uri_complete: format!(
"http://{}/device/verify?user_code={}",
host, &self.user_code
"{scheme}://{host}/device/verify?user_code={}",
&self.user_code
),
user_code: self.user_code,
device_code: self.device_code,
Expand Down
5 changes: 4 additions & 1 deletion nexus/src/external_api/device_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ pub async fn device_auth_request(

let model =
nexus.device_auth_request_create(&opctx, params.client_id).await?;
build_oauth_response(StatusCode::OK, &model.into_response(host))
build_oauth_response(
StatusCode::OK,
&model.into_response(rqctx.server.tls, host),
)
};
// TODO: instrumentation doesn't work because we use `Response<Body>`
//apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
Expand Down