Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "propelauth"
version = "0.21.0"
version = "0.22.0"
authors = ["support@propelauth.com"]
description = "A Rust crate for managing authentication and authorization with support for multi-tenant / B2B products, powered by PropelAuth"
keywords = ["authentication", "auth", "authorization", "b2b", "tenant"]
Expand Down
1 change: 1 addition & 0 deletions src/apis/api_key_service_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub enum ApiKeyError {
wait_seconds: f64,
user_facing_error: String,
},
PropelAuthRateLimit,
InvalidPersonalAPIKey,
InvalidOrgAPIKey,
NotFound,
Expand Down
2 changes: 2 additions & 0 deletions src/propelauth/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl AccessTokenService<'_> {
)),
) => CreateAccessTokenError::BadRequest(bad_request),
(401, _) => CreateAccessTokenError::InvalidApiKey,
(429, _) => CreateAccessTokenError::PropelAuthRateLimit,
(404, _) => CreateAccessTokenError::NotFound,
_ => CreateAccessTokenError::UnexpectedException,
},
Expand Down Expand Up @@ -61,6 +62,7 @@ impl AccessTokenService<'_> {
)),
) => CreateAccessTokenError::BadRequest(bad_request),
(401, _) => CreateAccessTokenError::InvalidApiKey,
(429, _) => CreateAccessTokenError::PropelAuthRateLimit,
(404, _) => CreateAccessTokenError::NotFound,
_ => CreateAccessTokenError::UnexpectedException,
},
Expand Down
70 changes: 53 additions & 17 deletions src/propelauth/api_key.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
use crate::apis::api_key_service_api::{ApiKeyError, ApiKeyQueryParams, ApiKeyValidationErrorResponse, CreateApiKeyParams, UpdateApiKeyParams, ValidateApiKeyParams};
use crate::apis::api_key_service_api::{
ApiKeyError, ApiKeyQueryParams, ApiKeyValidationErrorResponse, CreateApiKeyParams,
UpdateApiKeyParams, ValidateApiKeyParams,
};
use crate::apis::configuration::Configuration;
use crate::models::{CreateApiKeyResponse, FetchApiKeyResponse, FetchApiKeysPagedResponse, ValidateApiKeyResponse};
use crate::models::validate_api_key_response::{ValidateOrgApiKeyResponse, ValidatePersonalApiKeyResponse};
use crate::models::validate_api_key_response::{
ValidateOrgApiKeyResponse, ValidatePersonalApiKeyResponse,
};
use crate::models::{
CreateApiKeyResponse, FetchApiKeyResponse, FetchApiKeysPagedResponse, ValidateApiKeyResponse,
};
use crate::propelauth::helpers::map_autogenerated_error;

pub struct ApiKeyService<'a> {
pub(crate) config: &'a Configuration,
}

impl ApiKeyService<'_> {
pub async fn fetch_current_api_keys(&self, params: ApiKeyQueryParams) -> Result<FetchApiKeysPagedResponse, ApiKeyError> {
pub async fn fetch_current_api_keys(
&self,
params: ApiKeyQueryParams,
) -> Result<FetchApiKeysPagedResponse, ApiKeyError> {
crate::apis::api_key_service_api::fetch_current_api_keys(&self.config, params)
.await
.map_err(|err| {
Expand All @@ -20,18 +30,22 @@ impl ApiKeyService<'_> {
(
_,
Some(crate::apis::api_key_service_api::ApiKeyError::BadRequest(
bad_request,
)),
bad_request,
)),
) => ApiKeyError::BadRequest(bad_request),
(401, _) => ApiKeyError::InvalidIntegrationAPIKey,
(429, _) => ApiKeyError::PropelAuthRateLimit,
(404, _) => ApiKeyError::NotFound,
_ => ApiKeyError::UnexpectedExceptionWithSDK,
},
)
})
}

pub async fn fetch_archived_api_keys(&self, params: ApiKeyQueryParams) -> Result<FetchApiKeysPagedResponse, ApiKeyError> {
pub async fn fetch_archived_api_keys(
&self,
params: ApiKeyQueryParams,
) -> Result<FetchApiKeysPagedResponse, ApiKeyError> {
crate::apis::api_key_service_api::fetch_archived_api_keys(&self.config, params)
.await
.map_err(|err| {
Expand All @@ -42,18 +56,22 @@ impl ApiKeyService<'_> {
(
_,
Some(crate::apis::api_key_service_api::ApiKeyError::BadRequest(
bad_request,
)),
bad_request,
)),
) => ApiKeyError::BadRequest(bad_request),
(401, _) => ApiKeyError::InvalidIntegrationAPIKey,
(429, _) => ApiKeyError::PropelAuthRateLimit,
(404, _) => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
)
})
}

pub async fn fetch_api_key(&self, api_key_id: String) -> Result<FetchApiKeyResponse, ApiKeyError> {
pub async fn fetch_api_key(
&self,
api_key_id: String,
) -> Result<FetchApiKeyResponse, ApiKeyError> {
crate::apis::api_key_service_api::fetch_api_key(&self.config, api_key_id)
.await
.map_err(|err| {
Expand All @@ -62,14 +80,18 @@ impl ApiKeyService<'_> {
ApiKeyError::UnexpectedExceptionWithSDK,
|status_code, _| match status_code.as_u16() {
401 => ApiKeyError::InvalidIntegrationAPIKey,
429 => ApiKeyError::PropelAuthRateLimit,
404 => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
)
})
}

pub async fn create_api_key(&self, params: CreateApiKeyParams) -> Result<CreateApiKeyResponse, ApiKeyError> {
pub async fn create_api_key(
&self,
params: CreateApiKeyParams,
) -> Result<CreateApiKeyResponse, ApiKeyError> {
crate::apis::api_key_service_api::create_api_key(&self.config, params)
.await
.map_err(|err| {
Expand All @@ -78,14 +100,19 @@ impl ApiKeyService<'_> {
ApiKeyError::UnexpectedExceptionWithSDK,
|status_code, _| match status_code.as_u16() {
401 => ApiKeyError::InvalidIntegrationAPIKey,
429 => ApiKeyError::PropelAuthRateLimit,
404 => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
)
})
}

pub async fn update_api_key(&self, api_key_id: String, params: UpdateApiKeyParams) -> Result<(), ApiKeyError> {
pub async fn update_api_key(
&self,
api_key_id: String,
params: UpdateApiKeyParams,
) -> Result<(), ApiKeyError> {
crate::apis::api_key_service_api::update_api_key(&self.config, api_key_id, params)
.await
.map_err(|err| {
Expand All @@ -94,6 +121,7 @@ impl ApiKeyService<'_> {
ApiKeyError::UnexpectedExceptionWithSDK,
|status_code, _| match status_code.as_u16() {
401 => ApiKeyError::InvalidIntegrationAPIKey,
429 => ApiKeyError::PropelAuthRateLimit,
404 => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
Expand All @@ -112,6 +140,7 @@ impl ApiKeyService<'_> {
ApiKeyError::UnexpectedExceptionWithSDK,
|status_code, _| match status_code.as_u16() {
401 => ApiKeyError::InvalidIntegrationAPIKey,
429 => ApiKeyError::PropelAuthRateLimit,
404 => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
Expand All @@ -127,10 +156,10 @@ impl ApiKeyService<'_> {
) -> Result<ValidateApiKeyResponse, ApiKeyError> {
if hex::decode(&params.api_key_token).is_err() {
return Err(ApiKeyError::InvalidAPIKey {
message: "Invalid API key format.".to_string()
});
message: "Invalid API key format.".to_string(),
});
}

crate::apis::api_key_service_api::validate_api_key(&self.config, params)
.await
.map_err(|err| {
Expand All @@ -153,6 +182,7 @@ impl ApiKeyService<'_> {
},
None => match status_code.as_u16() {
401 => ApiKeyError::InvalidIntegrationAPIKey,
429 => ApiKeyError::PropelAuthRateLimit,
404 => ApiKeyError::NotFound,
_ => ApiKeyError::UnknownError,
},
Expand All @@ -161,7 +191,10 @@ impl ApiKeyService<'_> {
})
}

pub async fn validate_personal_api_key(&self, params: ValidateApiKeyParams) -> Result<ValidatePersonalApiKeyResponse, ApiKeyError> {
pub async fn validate_personal_api_key(
&self,
params: ValidateApiKeyParams,
) -> Result<ValidatePersonalApiKeyResponse, ApiKeyError> {
let resp = self.validate_api_key(params).await?;
if resp.user.is_none() || resp.org.is_some() {
return Err(ApiKeyError::InvalidPersonalAPIKey);
Expand All @@ -173,7 +206,10 @@ impl ApiKeyService<'_> {
})
}

pub async fn validate_org_api_key(&self, params: ValidateApiKeyParams) -> Result<ValidateOrgApiKeyResponse, ApiKeyError> {
pub async fn validate_org_api_key(
&self,
params: ValidateApiKeyParams,
) -> Result<ValidateOrgApiKeyResponse, ApiKeyError> {
let resp = self.validate_api_key(params).await?;
if resp.org.is_none() {
return Err(ApiKeyError::InvalidOrgAPIKey);
Expand Down
3 changes: 2 additions & 1 deletion src/propelauth/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use url::Url;
use crate::apis::auth_service_api::token_verification_metadata;
use crate::apis::configuration::Configuration;
use crate::models::AuthTokenVerificationMetadata;
use crate::propelauth::access_token::AccessTokenService;
use crate::propelauth::api_key::ApiKeyService;
use crate::propelauth::errors::InitializationError;
use crate::propelauth::helpers::map_autogenerated_error;
use crate::propelauth::options::{AuthOptions, AuthOptionsWithTokenVerification};
use crate::propelauth::org::OrgService;
use crate::propelauth::token::TokenService;
use crate::propelauth::user::UserService;
use crate::propelauth::access_token::AccessTokenService;

/// The main entrypoint of this library.
/// All authentication, authorization and API requests starts from this struct
Expand Down Expand Up @@ -57,6 +57,7 @@ impl PropelAuth {
InitializationError::UnexpectedException,
|status, _| match status.as_u16() {
401 => InitializationError::InvalidApiKey,
429 => InitializationError::PropelAuthRateLimit,
_ => InitializationError::UnexpectedException,
},
)
Expand Down
Loading
Loading