-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2/auth: add Basic authentication and refactor
This adds Basic authentication support. Along the way, the auth module has been refactored with new enums and structs to model the supported authentication mechanisms and make the response header parsing more robust. ***Breaking API changes*** * The `Client::login` and `Client::authenticate` methods have been merged into the latter. * `Client::is_auth` now performs a pure authentication test without attempting to authenticate, thus it no longer takes a token.
- Loading branch information
Showing
10 changed files
with
313 additions
and
184 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,23 +1 @@ | ||
extern crate futures; | ||
|
||
pub async fn authenticate_client( | ||
mut client: dkregistry::v2::Client, | ||
login_scope: String, | ||
) -> Result<dkregistry::v2::Client, dkregistry::errors::Error> { | ||
if !client.is_v2_supported().await? { | ||
return Err("API v2 not supported".into()); | ||
} | ||
|
||
if client.is_auth(None).await? { | ||
return Ok(client); | ||
} | ||
|
||
let token = client.login(&[login_scope.as_str()]).await?; | ||
|
||
if !client.is_auth(Some(token.token())).await? { | ||
Err("login failed".into()) | ||
} else { | ||
println!("logged in!"); | ||
Ok(client.set_token(Some(token.token())).clone()) | ||
} | ||
} |
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
Oops, something went wrong.