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

Move access token to auth #656

Merged
merged 2 commits into from
Mar 12, 2024
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
3 changes: 2 additions & 1 deletion crates/bitwarden/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- Switched TLS backend to `rustls`, removing the dependency on `OpenSSL`.
- Switched TLS backend to `rustls`, removing the dependency on `OpenSSL`. (#374)
- `client::AccessToken` is now `auth::AccessToken`. (#656)

## [0.4.0] - 2023-12-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl FromStr for AccessToken {
#[cfg(test)]
mod tests {

use super::AccessToken;

#[test]
fn can_decode_access_token() {
use std::str::FromStr;

use crate::client::AccessToken;

let access_token = "0.ec2c1d46-6a4b-4751-a310-af9601317f2d.C2IgxjjLF7qSshsbwe8JGcbM075YXw:X8vbvA0bduihIDe/qrzIQQ==";
let token = AccessToken::from_str(access_token).unwrap();

Expand All @@ -86,8 +86,6 @@ mod tests {
fn malformed_tokens() {
use std::str::FromStr;

use crate::client::AccessToken;

// Encryption key without base64 padding, we generate it with padding but ignore it when
// decoding
let t = "0.ec2c1d46-6a4b-4751-a310-af9601317f2d.C2IgxjjLF7qSshsbwe8JGcbM075YXw:X8vbvA0bduihIDe/qrzIQQ";
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 @@ -11,9 +11,9 @@ use crate::{
auth::{
api::{request::AccessTokenRequest, response::IdentityTokenResponse},
login::{response::two_factor::TwoFactorProviders, PasswordLoginResponse},
JWTToken,
AccessToken, JWTToken,
},
client::{AccessToken, LoginMethod, ServiceAccountLoginMethod},
client::{LoginMethod, ServiceAccountLoginMethod},
error::{Error, Result},
secrets_manager::state::{self, ClientState},
Client,
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden/src/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod access_token;
pub(super) mod api;
pub mod client_auth;
mod jwt_token;
pub mod login;
#[cfg(feature = "internal")]
pub mod password;
pub mod renew;
pub use access_token::AccessToken;
pub use jwt_token::JWTToken;
#[cfg(feature = "internal")]
mod register;
Expand Down
16 changes: 8 additions & 8 deletions crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ use chrono::Utc;
use reqwest::header::{self, HeaderValue};
use uuid::Uuid;

use super::AccessToken;
#[cfg(feature = "secrets")]
use crate::auth::login::{AccessTokenLoginRequest, AccessTokenLoginResponse};
use crate::{
auth::AccessToken,
client::{
client_settings::{ClientSettings, DeviceType},
encryption_settings::EncryptionSettings,
},
error::{Error, Result},
};
#[cfg(feature = "internal")]
use crate::{
client::flags::Flags,
Expand All @@ -20,13 +27,6 @@ use crate::{
UserApiKeyResponse,
},
};
use crate::{
client::{
client_settings::{ClientSettings, DeviceType},
encryption_settings::EncryptionSettings,
},
error::{Error, Result},
};

#[derive(Debug)]
pub(crate) struct ApiConfigurations {
Expand Down
2 changes: 0 additions & 2 deletions crates/bitwarden/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Bitwarden SDK Client

pub(crate) use client::*;
pub(crate) mod access_token;
#[allow(clippy::module_inception)]
mod client;
pub mod client_settings;
Expand All @@ -10,5 +9,4 @@ pub(crate) mod encryption_settings;
#[cfg(feature = "internal")]
mod flags;

pub use access_token::AccessToken;
pub use client::Client;
2 changes: 1 addition & 1 deletion crates/bitwarden/src/secrets_manager/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bitwarden_crypto::{EncString, KeyDecryptable, KeyEncryptable};
use serde::{Deserialize, Serialize};

use crate::{
client::AccessToken,
auth::AccessToken,
error::{Error, Result},
};

Expand Down
4 changes: 2 additions & 2 deletions crates/bws/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{path::PathBuf, process, str::FromStr};

use bitwarden::{
auth::login::AccessTokenLoginRequest,
client::{client_settings::ClientSettings, AccessToken},
auth::{login::AccessTokenLoginRequest, AccessToken},
client::client_settings::ClientSettings,
secrets_manager::{
projects::{
ProjectCreateRequest, ProjectGetRequest, ProjectPutRequest, ProjectsDeleteRequest,
Expand Down
Loading