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

Rename service_account_id to access_token_id #405

Merged
merged 1 commit into from
Dec 7, 2023
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
4 changes: 2 additions & 2 deletions crates/bitwarden/src/auth/api/request/access_token_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pub struct AccessTokenRequest {
}

impl AccessTokenRequest {
pub fn new(service_account_id: Uuid, client_secret: &String) -> Self {
pub fn new(access_token_id: Uuid, client_secret: &String) -> Self {
let obj = Self {
scope: "api.secrets".to_string(),
client_id: service_account_id.to_string(),
client_id: access_token_id.to_string(),
client_secret: client_secret.to_string(),
grant_type: "client_credentials".to_string(),
};
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/auth/login/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) async fn login_access_token(
r.refresh_token.clone(),
r.expires_in,
LoginMethod::ServiceAccount(ServiceAccountLoginMethod::AccessToken {
service_account_id: access_token.service_account_id,
access_token_id: access_token.access_token_id,
client_secret: access_token.client_secret,
organization_id,
}),
Expand All @@ -76,7 +76,7 @@ async fn request_access_token(
input: &AccessToken,
) -> Result<IdentityTokenResponse> {
let config = client.get_api_configurations().await;
AccessTokenRequest::new(input.service_account_id, &input.client_secret)
AccessTokenRequest::new(input.access_token_id, &input.client_secret)
.send(config)
.await
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/auth/renew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pub(crate) async fn renew_token(client: &mut Client) -> Result<()> {
},
LoginMethod::ServiceAccount(s) => match s {
ServiceAccountLoginMethod::AccessToken {
service_account_id,
access_token_id,
client_secret,
..
} => {
AccessTokenRequest::new(*service_account_id, client_secret)
AccessTokenRequest::new(*access_token_id, client_secret)
.send(&client.__api_configurations)
.await?
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bitwarden/src/client/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

pub struct AccessToken {
pub service_account_id: Uuid,
pub access_token_id: Uuid,
pub client_secret: String,
pub encryption_key: SymmetricCryptoKey,
}
Expand All @@ -22,7 +22,7 @@ impl FromStr for AccessToken {
let (first_part, encryption_key) =
key.split_once(':').ok_or(AccessTokenInvalidError::NoKey)?;

let [version, service_account_id, client_secret]: [&str; 3] = first_part
let [version, access_token_id, client_secret]: [&str; 3] = first_part
.split('.')
.collect::<Vec<_>>()
.try_into()
Expand All @@ -32,7 +32,7 @@ impl FromStr for AccessToken {
return Err(AccessTokenInvalidError::WrongVersion.into());
}

let Ok(service_account_id) = service_account_id.parse() else {
let Ok(access_token_id) = access_token_id.parse() else {
return Err(AccessTokenInvalidError::InvalidUuid.into());
};

Expand All @@ -49,7 +49,7 @@ impl FromStr for AccessToken {
derive_shareable_key(encryption_key, "accesstoken", Some("sm-access-token"));

Ok(AccessToken {
service_account_id,
access_token_id,
client_secret: client_secret.to_owned(),
encryption_key,
})
Expand All @@ -69,7 +69,7 @@ mod tests {
let token = AccessToken::from_str(access_token).unwrap();

assert_eq!(
&token.service_account_id.to_string(),
&token.access_token_id.to_string(),
"ec2c1d46-6a4b-4751-a310-af9601317f2d"
);
assert_eq!(token.client_secret, "C2IgxjjLF7qSshsbwe8JGcbM075YXw");
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) enum UserLoginMethod {
#[derive(Debug, Clone)]
pub(crate) enum ServiceAccountLoginMethod {
AccessToken {
service_account_id: Uuid,
access_token_id: Uuid,
client_secret: String,
organization_id: Uuid,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ async fn process_commands() -> Result<()> {
profile
} else if let Some(access_token) = cli.access_token {
AccessToken::from_str(&access_token)?
.service_account_id
.access_token_id
.to_string()
} else {
String::from("default")
Expand Down Expand Up @@ -619,7 +619,7 @@ fn get_config_profile(
profile.to_owned()
} else {
AccessToken::from_str(access_token)?
.service_account_id
.access_token_id
.to_string()
};

Expand Down