├── docs ├── OrgMetadata.md ├── FetchOrgOrderBy.md ├── FetchUsersOrderBy.md ├── MagicLink.md ├── EmailsQuery.md ├── UserIdsQuery.md ├── CreatedUserResponse.md ├── UsernamesQuery.md ├── UpdatePasswordRequest.md ├── SuccessfulResponse.md ├── BadCreateOrgRequest.md ├── BadUpdateOrgRequest.md ├── AuthTokenVerificationMetadata.md ├── BadFetchUsersByIdsQuery.md ├── CreateOrgResponse.md ├── BadFetchUsersByEmailsQuery.md ├── BadUpdatePasswordRequest.md ├── CreateAccessTokenResponse.md ├── BadFetchUsersByUsernamesQuery.md ├── BadUpdateUserEmailRequest.md ├── RemoveUserFromOrgRequest.md ├── UpdateEmailRequest.md ├── AddUserToOrgRequest.md ├── BadFetchOrgQuery.md ├── ChangeUserRoleInOrgRequest.md ├── BadFetchUsersInOrgQuery.md ├── CreateAccessTokenRequest.md ├── BadFetchUsersByQuery.md ├── UserInOrg.md ├── UserPagedResponse.md ├── FetchOrgsResponse.md ├── CreateMagicLinkRequest.md ├── CreateAccessTokenV2Request.md ├── BadUpdateUserMetadataRequest.md ├── BadCreateMagicLinkRequest.md ├── BadCreateUserRequest.md ├── CreateUserRequest.md ├── CreateOrgRequest.md ├── BadMigrateUserRequest.md ├── FetchOrgResponse.md ├── AuthServiceApi.md ├── UpdateOrgRequest.md ├── UserMetadata.md ├── UpdateMetadataRequest.md ├── AccessTokenServiceApi.md ├── MigrateUserRequest.md └── OrgServiceApi.md ├── src ├── propelauth │ ├── mod.rs │ ├── helpers.rs │ ├── options.rs │ ├── employee.rs │ ├── access_token.rs │ ├── auth.rs │ ├── mfa.rs │ └── token_models.rs ├── models │ ├── fetch_api_key_usage_response.rs │ ├── verify_grant_response.rs │ ├── fetch_saml_sp_metadata_response.rs │ ├── import_api_key_response.rs │ ├── send_sms_mfa_code_response.rs │ ├── create_access_token_response.rs │ ├── verify_sms_challenge_response.rs │ ├── verify_totp_challenge_response.rs │ ├── create_saml_connection_link_response.rs │ ├── resend_email_confirmation_request.rs │ ├── create_api_key_response.rs │ ├── fetch_custom_role_mappings_response.rs │ ├── subscribe_org_to_role_mapping_request.rs │ ├── fetch_user_signup_query_params_response.rs │ ├── magic_link.rs │ ├── bad_create_access_token_error.rs │ ├── emails_query.rs │ ├── user_ids_query.rs │ ├── fetch_api_key_response.rs │ ├── usernames_query.rs │ ├── created_user_response.rs │ ├── create_access_token_request.rs │ ├── update_password_request.rs │ ├── set_saml_idp_metadata_request.rs │ ├── successful_response.rs │ ├── bad_create_org_request.rs │ ├── bad_update_org_request.rs │ ├── create_access_token_v2_request.rs │ ├── bad_fetch_users_by_ids_query.rs │ ├── bad_update_password_request.rs │ ├── auth_token_verification_metadata.rs │ ├── bad_fetch_users_by_emails_query.rs │ ├── bad_update_user_email_request.rs │ ├── create_org_response.rs │ ├── bad_fetch_users_by_usernames_query.rs │ ├── remove_user_from_org_request.rs │ ├── migrate_user_password_request.rs │ ├── fetch_api_keys_response.rs │ ├── revoke_pending_org_invite_request.rs │ ├── update_email_request.rs │ ├── bad_fetch_org_query.rs │ ├── bad_fetch_users_in_org_query.rs │ ├── bad_migrate_user_password_request.rs │ ├── fetch_user_mfa_methods_response.rs │ ├── bad_fetch_users_by_query.rs │ ├── fetch_org_order_by.rs │ ├── invite_user_to_org_request.rs │ ├── user_paged_response.rs │ ├── fetch_orgs_response.rs │ ├── user_in_org.rs │ ├── bad_update_user_metadata_request.rs │ ├── fetch_pending_invites.rs │ ├── validate_api_key_response.rs │ ├── bad_create_magic_link_request.rs │ ├── bad_create_user_request.rs │ ├── add_user_to_org_request.rs │ ├── change_user_role_in_org_request.rs │ ├── create_magic_link_request.rs │ ├── fetch_users_order_by.rs │ ├── create_org_request.rs │ ├── bad_migrate_user_request.rs │ ├── update_metadata_request.rs │ ├── create_user_request.rs │ ├── update_org_request.rs │ ├── migrate_user_request.rs │ ├── user_metadata.rs │ ├── fetch_org_response.rs │ └── mod.rs ├── apis │ ├── configuration.rs │ ├── mod.rs │ ├── auth_service_api.rs │ ├── employee_service_api.rs │ ├── access_token_service_api.rs │ └── mfa_service_api.rs ├── actix │ └── mod.rs ├── axum08 │ └── mod.rs ├── axum06 │ └── mod.rs ├── axum07 │ └── mod.rs └── lib.rs ├── .github └── workflows │ ├── release.yaml │ └── test.yaml ├── Cargo.toml ├── .gitignore └── README.md /docs/OrgMetadata.md: -------------------------------------------------------------------------------- 1 | # OrgMetadata 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ------------ | -------------------------- | ----------- | ----- | 7 | | **metadata** | **HashMap** | | 8 | -------------------------------------------------------------------------------- /src/propelauth/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod api_key; 2 | pub mod auth; 3 | pub mod errors; 4 | pub(crate) mod helpers; 5 | pub mod options; 6 | pub mod org; 7 | pub mod token; 8 | pub mod token_models; 9 | pub mod user; 10 | pub mod access_token; 11 | pub mod employee; 12 | pub mod mfa; -------------------------------------------------------------------------------- /src/models/fetch_api_key_usage_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct FetchApiKeyUsageResponse { 3 | #[serde(rename = "count")] 4 | pub count: i64, 5 | } 6 | 7 | impl FetchApiKeyUsageResponse { 8 | pub fn new(count: i64) -> Self { 9 | Self { count } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/models/verify_grant_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct VerifyStepUpGrantResponse { 3 | #[serde(rename = "success")] 4 | pub success: bool, 5 | } 6 | 7 | impl VerifyStepUpGrantResponse { 8 | pub fn new(success: bool) -> Self { 9 | Self { success } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/FetchOrgOrderBy.md: -------------------------------------------------------------------------------- 1 | # FetchOrgOrderBy 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/FetchUsersOrderBy.md: -------------------------------------------------------------------------------- 1 | # FetchUsersOrderBy 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/models/fetch_saml_sp_metadata_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Deserialize)] 2 | pub struct FetchSamlSpMetadataResponse { 3 | #[serde(rename = "entity_id")] 4 | pub entity_id: String, 5 | #[serde(rename = "acs_url")] 6 | pub acs_url: String, 7 | #[serde(rename = "logout_url")] 8 | pub logout_url: String, 9 | } 10 | -------------------------------------------------------------------------------- /src/models/import_api_key_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct ImportApiKeyResponse { 3 | pub api_key_id: String, 4 | } 5 | 6 | impl ImportApiKeyResponse { 7 | pub fn new(api_key_id: String) -> Self { 8 | ImportApiKeyResponse { 9 | api_key_id, 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/models/send_sms_mfa_code_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct SendSmsCodeResponse { 3 | #[serde(rename = "challenge_id")] 4 | pub challenge_id: String, 5 | } 6 | 7 | impl SendSmsCodeResponse { 8 | pub fn new(challenge_id: String) -> Self { 9 | Self { challenge_id } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/MagicLink.md: -------------------------------------------------------------------------------- 1 | # MagicLink 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **url** | **String** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/EmailsQuery.md: -------------------------------------------------------------------------------- 1 | # EmailsQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **emails** | **Vec** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/models/create_access_token_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct CreateAccessTokenResponse { 3 | pub access_token: String, 4 | } 5 | 6 | impl CreateAccessTokenResponse { 7 | pub fn new(access_token: String) -> Self { 8 | CreateAccessTokenResponse { 9 | access_token, 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/models/verify_sms_challenge_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct VerifySmsChallengeResponse { 3 | #[serde(rename = "step_up_grant")] 4 | pub step_up_grant: String, 5 | } 6 | 7 | impl VerifySmsChallengeResponse { 8 | pub fn new(step_up_grant: String) -> Self { 9 | Self { step_up_grant } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/UserIdsQuery.md: -------------------------------------------------------------------------------- 1 | # UserIdsQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_ids** | **Vec** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/models/verify_totp_challenge_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct VerifyTotpChallengeResponse { 3 | #[serde(rename = "step_up_grant")] 4 | pub step_up_grant: String, 5 | } 6 | 7 | impl VerifyTotpChallengeResponse { 8 | pub fn new(step_up_grant: String) -> Self { 9 | Self { step_up_grant } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/CreatedUserResponse.md: -------------------------------------------------------------------------------- 1 | # CreatedUserResponse 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_id** | **String** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/UsernamesQuery.md: -------------------------------------------------------------------------------- 1 | # UsernamesQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **usernames** | **Vec** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/UpdatePasswordRequest.md: -------------------------------------------------------------------------------- 1 | # UpdatePasswordRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **password** | **String** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/SuccessfulResponse.md: -------------------------------------------------------------------------------- 1 | # SuccessfulResponse 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **message** | Option<**String**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/BadCreateOrgRequest.md: -------------------------------------------------------------------------------- 1 | # BadCreateOrgRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **name** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/BadUpdateOrgRequest.md: -------------------------------------------------------------------------------- 1 | # BadUpdateOrgRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **name** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/models/create_saml_connection_link_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct CreateSamlConnectionLinkResponse { 3 | #[serde(rename = "url")] 4 | pub url: String, 5 | } 6 | 7 | impl CreateSamlConnectionLinkResponse { 8 | pub fn new(url: String) -> CreateSamlConnectionLinkResponse { 9 | CreateSamlConnectionLinkResponse { url } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/AuthTokenVerificationMetadata.md: -------------------------------------------------------------------------------- 1 | # AuthTokenVerificationMetadata 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **public_key_pem** | **String** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/BadFetchUsersByIdsQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchUsersByIdsQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **query** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/CreateOrgResponse.md: -------------------------------------------------------------------------------- 1 | # CreateOrgResponse 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **org_id** | **String** | | 8 | **name** | **String** | | 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/models/resend_email_confirmation_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct ResendEmailConfirmationRequest { 3 | #[serde(rename = "user_id")] 4 | pub user_id: String, 5 | } 6 | 7 | impl ResendEmailConfirmationRequest { 8 | pub fn new(user_id: String) -> ResendEmailConfirmationRequest { 9 | ResendEmailConfirmationRequest { user_id } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /docs/BadFetchUsersByEmailsQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchUsersByEmailsQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **query** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/BadUpdatePasswordRequest.md: -------------------------------------------------------------------------------- 1 | # BadUpdatePasswordRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **password** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/CreateAccessTokenResponse.md: -------------------------------------------------------------------------------- 1 | # CreateAccessTokenResponse 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---------------- | ---------- | ----------- | ----- | 7 | | **access_token** | **String** | | 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | -------------------------------------------------------------------------------- /docs/BadFetchUsersByUsernamesQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchUsersByUsernamesQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **query** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/BadUpdateUserEmailRequest.md: -------------------------------------------------------------------------------- 1 | # BadUpdateUserEmailRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **new_email** | Option<**Vec**> | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs/RemoveUserFromOrgRequest.md: -------------------------------------------------------------------------------- 1 | # RemoveUserFromOrgRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_id** | **String** | | 8 | **org_id** | **String** | | 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/UpdateEmailRequest.md: -------------------------------------------------------------------------------- 1 | # UpdateEmailRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **new_email** | **String** | | 8 | **require_email_confirmation** | **bool** | | 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/models/create_api_key_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct CreateApiKeyResponse { 3 | pub api_key_id: String, 4 | pub api_key_token: String, 5 | } 6 | 7 | impl CreateApiKeyResponse { 8 | pub fn new(api_key_id: String, api_key_token: String) -> Self { 9 | CreateApiKeyResponse { 10 | api_key_id, 11 | api_key_token, 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: cargo publish 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | build_and_publish: 7 | name: Rust project 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions-rs/toolchain@v1 12 | with: 13 | toolchain: stable 14 | - run: cargo publish 15 | env: 16 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} 17 | -------------------------------------------------------------------------------- /docs/AddUserToOrgRequest.md: -------------------------------------------------------------------------------- 1 | # AddUserToOrgRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_id** | **String** | | 8 | **org_id** | **String** | | 9 | **role** | **String** | | 10 | 11 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/BadFetchOrgQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchOrgQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **page_size** | Option<**Vec**> | | [optional] 8 | **page_number** | Option<**Vec**> | | [optional] 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/ChangeUserRoleInOrgRequest.md: -------------------------------------------------------------------------------- 1 | # ChangeUserRoleInOrgRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_id** | **String** | | 8 | **org_id** | **String** | | 9 | **role** | **String** | | 10 | 11 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/BadFetchUsersInOrgQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchUsersInOrgQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **page_size** | Option<**Vec**> | | [optional] 8 | **page_number** | Option<**Vec**> | | [optional] 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /docs/CreateAccessTokenRequest.md: -------------------------------------------------------------------------------- 1 | # CreateAccessTokenRequest 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ----------------------- | ---------- | ----------- | ----- | 7 | | **user_id** | **String** | | 8 | | **duration_in_minutes** | **u64** | | 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | -------------------------------------------------------------------------------- /src/models/fetch_custom_role_mappings_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Deserialize, Debug)] 2 | pub struct FetchCustomRoleMappingsResponse { 3 | #[serde(rename = "custom_role_mappings", default)] 4 | pub custom_role_mappings: Vec, 5 | } 6 | 7 | #[derive(Deserialize, Debug)] 8 | pub struct CustomRoleMappingResponse { 9 | #[serde(rename = "custom_role_mapping_name")] 10 | pub custom_role_mapping_name: String, 11 | #[serde(rename = "num_orgs_subscribed")] 12 | pub num_orgs_subscribed: i32, 13 | } 14 | -------------------------------------------------------------------------------- /src/models/subscribe_org_to_role_mapping_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct SubscribeOrgToRoleMappingRequest { 3 | #[serde(rename = "custom_role_mapping_name")] 4 | pub custom_role_mapping_name: String, 5 | } 6 | 7 | impl SubscribeOrgToRoleMappingRequest { 8 | pub fn new(custom_role_mapping_name: String) -> SubscribeOrgToRoleMappingRequest { 9 | SubscribeOrgToRoleMappingRequest { 10 | custom_role_mapping_name, 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/BadFetchUsersByQuery.md: -------------------------------------------------------------------------------- 1 | # BadFetchUsersByQuery 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **page_size** | Option<**Vec**> | | [optional] 8 | **page_number** | Option<**Vec**> | | [optional] 9 | **email_or_username** | Option<**Vec**> | | [optional] 10 | 11 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/UserInOrg.md: -------------------------------------------------------------------------------- 1 | # UserInOrg 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **org_id** | **String** | | 8 | **org_name** | **String** | | 9 | **user_role** | **String** | | 10 | **inherited_user_roles_plus_current_role** | **Vec** | | 11 | **user_permissions** | **Vec** | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/models/fetch_user_signup_query_params_response.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use serde_json::Value; 4 | 5 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 6 | pub struct FetchSignupQueryParamsResponse { 7 | #[serde(rename = "user_signup_query_parameters")] 8 | pub user_signup_query_parameters: HashMap, 9 | } 10 | 11 | impl FetchSignupQueryParamsResponse { 12 | pub fn new(user_signup_query_parameters: HashMap) -> Self { 13 | Self { user_signup_query_parameters } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | on: [push] 2 | 3 | name: CI 4 | 5 | jobs: 6 | build_and_test: 7 | name: Rust project 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: actions-rs/toolchain@v1 12 | with: 13 | toolchain: stable 14 | - name: Run tests 15 | uses: actions-rs/cargo@v1 16 | with: 17 | command: test 18 | - name: Build Library Release 19 | uses: actions-rs/cargo@v1 20 | with: 21 | command: build 22 | args: --release --all-features 23 | -------------------------------------------------------------------------------- /docs/UserPagedResponse.md: -------------------------------------------------------------------------------- 1 | # UserPagedResponse 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **users** | [**Vec**](UserMetadata.md) | | 8 | **total_users** | **i64** | | 9 | **current_page** | **i64** | | 10 | **page_size** | **i64** | | 11 | **has_more_results** | **bool** | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/FetchOrgsResponse.md: -------------------------------------------------------------------------------- 1 | # FetchOrgsResponse 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **orgs** | [**Vec**](FetchOrgResponse.md) | | 8 | **total_orgs** | **i64** | | 9 | **current_page** | **i64** | | 10 | **page_size** | **i64** | | 11 | **has_more_results** | **bool** | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/CreateMagicLinkRequest.md: -------------------------------------------------------------------------------- 1 | # CreateMagicLinkRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **email** | **String** | | 8 | **redirect_to_url** | Option<**String**> | | [optional] 9 | **expires_in_hours** | Option<**i64**> | | [optional] 10 | **create_new_user_if_one_doesnt_exist** | Option<**bool**> | | [optional] 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/CreateAccessTokenV2Request.md: -------------------------------------------------------------------------------- 1 | # CreateAccessTokenV2Request 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ----------------------- | ------------------ | ----------- | ----- | 7 | | **user_id** | **String** | | 8 | | **duration_in_minutes** | **u64** | | 9 | | **active_org_id** | **Option** | | 10 | 11 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 12 | -------------------------------------------------------------------------------- /docs/BadUpdateUserMetadataRequest.md: -------------------------------------------------------------------------------- 1 | # BadUpdateUserMetadataRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **username** | Option<**Vec**> | | [optional] 8 | **first_name** | Option<**Vec**> | | [optional] 9 | **last_name** | Option<**Vec**> | | [optional] 10 | **picture_url** | Option<**Vec**> | | [optional] 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /docs/BadCreateMagicLinkRequest.md: -------------------------------------------------------------------------------- 1 | # BadCreateMagicLinkRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **email** | Option<**Vec**> | | [optional] 8 | **redirect_to_url** | Option<**Vec**> | | [optional] 9 | **expires_in_hours** | Option<**Vec**> | | [optional] 10 | **create_new_user_if_one_doesnt_exist** | Option<**Vec**> | | [optional] 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/models/magic_link.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct MagicLink { 16 | #[serde(rename = "url")] 17 | pub url: String, 18 | } 19 | 20 | impl MagicLink { 21 | pub fn new(url: String) -> MagicLink { 22 | MagicLink { 23 | url, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_create_access_token_error.rs: -------------------------------------------------------------------------------- 1 | 2 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 3 | pub struct BadCreateAccessTokenError { 4 | #[serde(rename = "active_org_id", skip_serializing_if = "Option::is_none")] 5 | pub active_org_id: Option>, 6 | #[serde(rename = "user_id", skip_serializing_if = "Option::is_none")] 7 | pub user_id: Option>, 8 | } 9 | 10 | impl BadCreateAccessTokenError { 11 | pub fn new() -> BadCreateAccessTokenError { 12 | BadCreateAccessTokenError { 13 | active_org_id: None, 14 | user_id: None, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/BadCreateUserRequest.md: -------------------------------------------------------------------------------- 1 | # BadCreateUserRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **email** | Option<**Vec**> | | [optional] 8 | **username** | Option<**Vec**> | | [optional] 9 | **password** | Option<**Vec**> | | [optional] 10 | **first_name** | Option<**Vec**> | | [optional] 11 | **last_name** | Option<**Vec**> | | [optional] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/models/emails_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct EmailsQuery { 16 | #[serde(rename = "emails")] 17 | pub emails: Vec, 18 | } 19 | 20 | impl EmailsQuery { 21 | pub fn new(emails: Vec) -> EmailsQuery { 22 | EmailsQuery { 23 | emails, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/user_ids_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct UserIdsQuery { 16 | #[serde(rename = "user_ids")] 17 | pub user_ids: Vec, 18 | } 19 | 20 | impl UserIdsQuery { 21 | pub fn new(user_ids: Vec) -> UserIdsQuery { 22 | UserIdsQuery { 23 | user_ids, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/fetch_api_key_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct FetchApiKeyResponse { 3 | pub api_key_id: String, 4 | pub created_at: i32, 5 | pub expires_at_seconds: Option, 6 | pub metadata: Option, 7 | pub user_id: Option, 8 | pub org_id: Option, 9 | } 10 | 11 | impl FetchApiKeyResponse { 12 | pub fn new(api_key_id: String, created_at: i32, expires_at_seconds: Option, metadata: Option, user_id: Option, org_id: Option) -> Self { 13 | Self { api_key_id, created_at, expires_at_seconds, metadata, user_id, org_id } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/models/usernames_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct UsernamesQuery { 16 | #[serde(rename = "usernames")] 17 | pub usernames: Vec, 18 | } 19 | 20 | impl UsernamesQuery { 21 | pub fn new(usernames: Vec) -> UsernamesQuery { 22 | UsernamesQuery { 23 | usernames, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/CreateUserRequest.md: -------------------------------------------------------------------------------- 1 | # CreateUserRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **email** | **String** | | 8 | **email_confirmed** | **bool** | | 9 | **send_email_to_confirm_email_address** | **bool** | | 10 | **password** | Option<**String**> | | [optional] 11 | **username** | Option<**String**> | | [optional] 12 | **first_name** | Option<**String**> | | [optional] 13 | **last_name** | Option<**String**> | | [optional] 14 | 15 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/models/created_user_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct CreatedUserResponse { 16 | #[serde(rename = "user_id")] 17 | pub user_id: String, 18 | } 19 | 20 | impl CreatedUserResponse { 21 | pub fn new(user_id: String) -> CreatedUserResponse { 22 | CreatedUserResponse { 23 | user_id, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/create_access_token_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct CreateAccessTokenRequest { 3 | #[serde(rename = "user_id")] 4 | pub user_id: String, 5 | #[serde(rename = "duration_in_minutes")] 6 | pub duration_in_minutes: u64, 7 | #[serde(rename = "active_org_id")] 8 | pub active_org_id: Option, 9 | } 10 | 11 | impl CreateAccessTokenRequest { 12 | pub fn new(user_id: String, duration_in_minutes: u64, active_org_id: Option) -> CreateAccessTokenRequest { 13 | CreateAccessTokenRequest { 14 | user_id, 15 | duration_in_minutes, 16 | active_org_id 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/models/update_password_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct UpdatePasswordRequest { 16 | #[serde(rename = "password")] 17 | pub password: String, 18 | } 19 | 20 | impl UpdatePasswordRequest { 21 | pub fn new(password: String) -> UpdatePasswordRequest { 22 | UpdatePasswordRequest { 23 | password, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/propelauth/helpers.rs: -------------------------------------------------------------------------------- 1 | use crate::apis::Error; 2 | use uuid::Uuid; 3 | 4 | pub fn map_autogenerated_error(err: Error, unexpected_error: U, map: M) -> U 5 | where 6 | M: Fn(reqwest::StatusCode, Option) -> U, 7 | { 8 | match err { 9 | Error::Reqwest(_) => return unexpected_error, 10 | Error::Serde(_) => return unexpected_error, 11 | Error::Io(_) => return unexpected_error, 12 | Error::Params(_) => return unexpected_error, 13 | Error::ResponseError(response_content) => { 14 | map(response_content.status, response_content.entity) 15 | } 16 | } 17 | } 18 | 19 | pub fn is_valid_id(id: &str) -> bool { 20 | Uuid::parse_str(id).is_ok() 21 | } 22 | -------------------------------------------------------------------------------- /src/models/set_saml_idp_metadata_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Serialize)] 2 | pub struct SetSamlIdpMetadataRequest { 3 | #[serde(rename = "org_id")] 4 | pub org_id: String, 5 | #[serde(rename = "idp_entity_id")] 6 | pub idp_entity_id: String, 7 | #[serde(rename = "idp_sso_url")] 8 | pub idp_sso_url: String, 9 | #[serde(rename = "idp_certificate")] 10 | pub idp_certificate: String, 11 | #[serde(rename = "provider")] 12 | pub provider: SamlIdpProvider, 13 | } 14 | 15 | #[derive(Clone, Debug, PartialEq, Serialize)] 16 | pub enum SamlIdpProvider { 17 | Google, 18 | Rippling, 19 | OneLogin, 20 | JumpCloud, 21 | Okta, 22 | Azure, 23 | Duo, 24 | Generic, 25 | } 26 | -------------------------------------------------------------------------------- /src/models/successful_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct SuccessfulResponse { 16 | #[serde(rename = "message", skip_serializing_if = "Option::is_none")] 17 | pub message: Option, 18 | } 19 | 20 | impl SuccessfulResponse { 21 | pub fn new() -> SuccessfulResponse { 22 | SuccessfulResponse { 23 | message: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_create_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadCreateOrgRequest { 16 | #[serde(rename = "name", skip_serializing_if = "Option::is_none")] 17 | pub name: Option>, 18 | } 19 | 20 | impl BadCreateOrgRequest { 21 | pub fn new() -> BadCreateOrgRequest { 22 | BadCreateOrgRequest { 23 | name: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_update_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadUpdateOrgRequest { 16 | #[serde(rename = "name", skip_serializing_if = "Option::is_none")] 17 | pub name: Option>, 18 | } 19 | 20 | impl BadUpdateOrgRequest { 21 | pub fn new() -> BadUpdateOrgRequest { 22 | BadUpdateOrgRequest { 23 | name: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/create_access_token_v2_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | 3 | pub struct CreateAccessTokenV2Request { 4 | #[serde(rename = "user_id")] 5 | pub user_id: String, 6 | #[serde(rename = "duration_in_minutes")] 7 | pub duration_in_minutes: u64, 8 | 9 | #[serde(rename = "active_org_id", skip_serializing_if = "Option::is_none")] 10 | pub active_org_id: Option, 11 | } 12 | 13 | impl CreateAccessTokenV2Request { 14 | pub fn new(user_id: String, duration_in_minutes: u64) -> CreateAccessTokenV2Request { 15 | CreateAccessTokenV2Request { 16 | user_id, 17 | duration_in_minutes, 18 | active_org_id: None, 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/models/bad_fetch_users_by_ids_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchUsersByIdsQuery { 16 | #[serde(rename = "query", skip_serializing_if = "Option::is_none")] 17 | pub query: Option>, 18 | } 19 | 20 | impl BadFetchUsersByIdsQuery { 21 | pub fn new() -> BadFetchUsersByIdsQuery { 22 | BadFetchUsersByIdsQuery { 23 | query: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_update_password_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadUpdatePasswordRequest { 16 | #[serde(rename = "password", skip_serializing_if = "Option::is_none")] 17 | pub password: Option>, 18 | } 19 | 20 | impl BadUpdatePasswordRequest { 21 | pub fn new() -> BadUpdatePasswordRequest { 22 | BadUpdatePasswordRequest { 23 | password: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/auth_token_verification_metadata.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct AuthTokenVerificationMetadata { 16 | #[serde(rename = "public_key_pem")] 17 | pub public_key_pem: String, 18 | } 19 | 20 | impl AuthTokenVerificationMetadata { 21 | pub fn new(public_key_pem: String) -> AuthTokenVerificationMetadata { 22 | AuthTokenVerificationMetadata { 23 | public_key_pem, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_fetch_users_by_emails_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchUsersByEmailsQuery { 16 | #[serde(rename = "query", skip_serializing_if = "Option::is_none")] 17 | pub query: Option>, 18 | } 19 | 20 | impl BadFetchUsersByEmailsQuery { 21 | pub fn new() -> BadFetchUsersByEmailsQuery { 22 | BadFetchUsersByEmailsQuery { 23 | query: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/bad_update_user_email_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadUpdateUserEmailRequest { 16 | #[serde(rename = "new_email", skip_serializing_if = "Option::is_none")] 17 | pub new_email: Option>, 18 | } 19 | 20 | impl BadUpdateUserEmailRequest { 21 | pub fn new() -> BadUpdateUserEmailRequest { 22 | BadUpdateUserEmailRequest { 23 | new_email: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/models/create_org_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct CreateOrgResponse { 16 | #[serde(rename = "org_id")] 17 | pub org_id: String, 18 | #[serde(rename = "name")] 19 | pub name: String, 20 | } 21 | 22 | impl CreateOrgResponse { 23 | pub fn new(org_id: String, name: String) -> CreateOrgResponse { 24 | CreateOrgResponse { 25 | org_id, 26 | name, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/bad_fetch_users_by_usernames_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchUsersByUsernamesQuery { 16 | #[serde(rename = "query", skip_serializing_if = "Option::is_none")] 17 | pub query: Option>, 18 | } 19 | 20 | impl BadFetchUsersByUsernamesQuery { 21 | pub fn new() -> BadFetchUsersByUsernamesQuery { 22 | BadFetchUsersByUsernamesQuery { 23 | query: None, 24 | } 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/CreateOrgRequest.md: -------------------------------------------------------------------------------- 1 | # CreateOrgRequest 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ------------------------------------- | ------------------ | ----------- | ----- | 7 | | **name** | **String** | | 8 | | **domain** | **Option** | | 9 | | **enable_auto_joining_by_domain** | **Option** | | 10 | | **members_must_have_matching_domain** | **Option** | | 11 | | **max_users** | **Option** | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | -------------------------------------------------------------------------------- /docs/BadMigrateUserRequest.md: -------------------------------------------------------------------------------- 1 | # BadMigrateUserRequest 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **email** | Option<**Vec**> | | [optional] 8 | **existing_user_id** | Option<**Vec**> | | [optional] 9 | **existing_password_hash** | Option<**Vec**> | | [optional] 10 | **existing_mfa_base32_encoded_secret** | Option<**Vec**> | | [optional] 11 | **username** | Option<**Vec**> | | [optional] 12 | **first_name** | Option<**Vec**> | | [optional] 13 | **last_name** | Option<**Vec**> | | [optional] 14 | 15 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/FetchOrgResponse.md: -------------------------------------------------------------------------------- 1 | # FetchOrgResponse 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---------------------- | --------------------------------- | ----------- | ---------- | 7 | | **org_id** | **String** | | 8 | | **name** | **String** | | 9 | | **is_saml_configured** | **bool** | | 10 | | **metadata** | [**OrgMetadata**](OrgMetadata.md) | | 11 | | **max_users** | **int** | | [optional] | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | -------------------------------------------------------------------------------- /src/models/remove_user_from_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct RemoveUserFromOrgRequest { 16 | #[serde(rename = "user_id")] 17 | pub user_id: String, 18 | #[serde(rename = "org_id")] 19 | pub org_id: String, 20 | } 21 | 22 | impl RemoveUserFromOrgRequest { 23 | pub fn new(user_id: String, org_id: String) -> RemoveUserFromOrgRequest { 24 | RemoveUserFromOrgRequest { 25 | user_id, 26 | org_id, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/migrate_user_password_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 12 | pub struct MigrateUserPasswordRequest { 13 | #[serde(rename = "user_id")] 14 | pub user_id: String, 15 | #[serde(rename = "password_hash")] 16 | pub password_hash: String, 17 | } 18 | 19 | impl MigrateUserPasswordRequest { 20 | pub fn new(user_id: String, password_hash: String) -> MigrateUserPasswordRequest { 21 | MigrateUserPasswordRequest { 22 | user_id, 23 | password_hash, 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/models/fetch_api_keys_response.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct FetchApiKeysPagedResponse { 3 | #[serde(rename = "api_keys")] 4 | pub api_keys: Vec, 5 | #[serde(rename = "total_api_keys")] 6 | pub total_api_keys: i64, 7 | #[serde(rename = "current_page")] 8 | pub current_page: i64, 9 | #[serde(rename = "page_size")] 10 | pub page_size: i64, 11 | #[serde(rename = "has_more_results")] 12 | pub has_more_results: bool, 13 | } 14 | 15 | impl FetchApiKeysPagedResponse { 16 | pub fn new(api_keys: Vec, total_api_keys: i64, current_page: i64, page_size: i64, has_more_results: bool) -> Self { 17 | Self { api_keys, total_api_keys, current_page, page_size, has_more_results } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/models/revoke_pending_org_invite_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 12 | pub struct RevokePendingOrgInviteRequest { 13 | #[serde(rename = "org_id")] 14 | pub org_id: String, 15 | #[serde(rename = "invitee_email")] 16 | pub invitee_email: String, 17 | } 18 | 19 | impl RevokePendingOrgInviteRequest { 20 | pub fn new(org_id: String, invitee_email: String) -> RevokePendingOrgInviteRequest { 21 | RevokePendingOrgInviteRequest { 22 | org_id, 23 | invitee_email, 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/models/update_email_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct UpdateEmailRequest { 16 | #[serde(rename = "new_email")] 17 | pub new_email: String, 18 | #[serde(rename = "require_email_confirmation")] 19 | pub require_email_confirmation: bool, 20 | } 21 | 22 | impl UpdateEmailRequest { 23 | pub fn new(new_email: String, require_email_confirmation: bool) -> UpdateEmailRequest { 24 | UpdateEmailRequest { 25 | new_email, 26 | require_email_confirmation, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/bad_fetch_org_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchOrgQuery { 16 | #[serde(rename = "page_size", skip_serializing_if = "Option::is_none")] 17 | pub page_size: Option>, 18 | #[serde(rename = "page_number", skip_serializing_if = "Option::is_none")] 19 | pub page_number: Option>, 20 | } 21 | 22 | impl BadFetchOrgQuery { 23 | pub fn new() -> BadFetchOrgQuery { 24 | BadFetchOrgQuery { 25 | page_size: None, 26 | page_number: None, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/bad_fetch_users_in_org_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchUsersInOrgQuery { 16 | #[serde(rename = "page_size", skip_serializing_if = "Option::is_none")] 17 | pub page_size: Option>, 18 | #[serde(rename = "page_number", skip_serializing_if = "Option::is_none")] 19 | pub page_number: Option>, 20 | } 21 | 22 | impl BadFetchUsersInOrgQuery { 23 | pub fn new() -> BadFetchUsersInOrgQuery { 24 | BadFetchUsersInOrgQuery { 25 | page_size: None, 26 | page_number: None, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/bad_migrate_user_password_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadMigrateUserPasswordRequest { 16 | #[serde(rename = "user_id", skip_serializing_if = "Option::is_none")] 17 | pub user_id: Option>, 18 | #[serde(rename = "password_hash", skip_serializing_if = "Option::is_none")] 19 | pub password_hash: Option>, 20 | } 21 | 22 | impl BadMigrateUserPasswordRequest { 23 | pub fn new() -> BadMigrateUserPasswordRequest { 24 | BadMigrateUserPasswordRequest { 25 | user_id: None, 26 | password_hash: None, 27 | } 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/models/fetch_user_mfa_methods_response.rs: -------------------------------------------------------------------------------- 1 | 2 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 3 | pub struct MfaPhones { 4 | #[serde(rename = "mfa_phone_number_suffix")] 5 | pub mfa_phone_number_suffix: String, 6 | #[serde(rename = "mfa_phone_id")] 7 | pub mfa_phone_id: String 8 | } 9 | 10 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 11 | pub struct MfaSetupType { 12 | #[serde(rename = "type")] 13 | pub type_: String, 14 | #[serde(rename = "phone_numbers")] 15 | pub phone_numbers: Option>, 16 | } 17 | 18 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 19 | pub struct FetchUserMfaMethodsResponse { 20 | #[serde(rename = "mfa_setup")] 21 | pub mfa_setup: Option, 22 | } 23 | 24 | impl FetchUserMfaMethodsResponse { 25 | pub fn new(mfa_setup: Option) -> Self { 26 | FetchUserMfaMethodsResponse { 27 | mfa_setup, 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/AuthServiceApi.md: -------------------------------------------------------------------------------- 1 | # \AuthServiceApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**token_verification_metadata**](AuthServiceApi.md#token_verification_metadata) | **GET** /api/backend/v1/token_verification_metadata | 8 | 9 | 10 | 11 | ## token_verification_metadata 12 | 13 | > crate::models::AuthTokenVerificationMetadata token_verification_metadata() 14 | 15 | 16 | ### Parameters 17 | 18 | This endpoint does not need any parameter. 19 | 20 | ### Return type 21 | 22 | [**crate::models::AuthTokenVerificationMetadata**](AuthTokenVerificationMetadata.md) 23 | 24 | ### Authorization 25 | 26 | [BearerAuth](../README.md#BearerAuth) 27 | 28 | ### HTTP request headers 29 | 30 | - **Content-Type**: Not defined 31 | - **Accept**: application/json 32 | 33 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 34 | 35 | -------------------------------------------------------------------------------- /docs/UpdateOrgRequest.md: -------------------------------------------------------------------------------- 1 | # UpdateOrgRequest 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---------------------- | ---------------------------------- | ----------- | ---------- | 7 | | **name** | Option<**String**> | | [optional] | 8 | | **can_setup_saml** | Option<**bool**> | | [optional] | 9 | | **max_users** | Option<**i32**> | | [optional] | 10 | | **metadata** | Option<**HashMap**> | | [optional] | 11 | | **domain** | Option<**String**> | | [optional] | 12 | | **autojoin_by_domain** | Option<**bool**> | | [optional] | 13 | | **restrict_to_domain** | Option<**bool**> | | [optional] | 14 | 15 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 16 | -------------------------------------------------------------------------------- /docs/UserMetadata.md: -------------------------------------------------------------------------------- 1 | # UserMetadata 2 | 3 | ## Properties 4 | 5 | Name | Type | Description | Notes 6 | ------------ | ------------- | ------------- | ------------- 7 | **user_id** | **String** | | 8 | **email** | **String** | | 9 | **email_confirmed** | **bool** | | 10 | **has_password** | **bool** | | 11 | **username** | Option<**String**> | | [optional] 12 | **first_name** | Option<**String**> | | [optional] 13 | **last_name** | Option<**String**> | | [optional] 14 | **picture_url** | Option<**String**> | | [optional] 15 | **locked** | **bool** | | 16 | **enabled** | **bool** | | 17 | **mfa_enabled** | **bool** | | 18 | **created_at** | **i64** | | 19 | **last_active_at** | **i64** | | 20 | **org_id_to_org_info** | Option<[**::std::collections::HashMap**](UserInOrg.md)> | | [optional] 21 | **legacy_user_id** | Option<**String**> | | [optional] 22 | 23 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/models/bad_fetch_users_by_query.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadFetchUsersByQuery { 16 | #[serde(rename = "page_size", skip_serializing_if = "Option::is_none")] 17 | pub page_size: Option>, 18 | #[serde(rename = "page_number", skip_serializing_if = "Option::is_none")] 19 | pub page_number: Option>, 20 | #[serde(rename = "email_or_username", skip_serializing_if = "Option::is_none")] 21 | pub email_or_username: Option>, 22 | } 23 | 24 | impl BadFetchUsersByQuery { 25 | pub fn new() -> BadFetchUsersByQuery { 26 | BadFetchUsersByQuery { 27 | page_size: None, 28 | page_number: None, 29 | email_or_username: None, 30 | } 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/models/fetch_org_order_by.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | /// 13 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] 14 | pub enum FetchOrgOrderBy { 15 | #[serde(rename = "CREATED_AT_ASC")] 16 | CreatedAtAsc, 17 | #[serde(rename = "CREATED_AT_DESC")] 18 | CreatedAtDesc, 19 | #[serde(rename = "NAME")] 20 | Name, 21 | 22 | } 23 | 24 | impl ToString for FetchOrgOrderBy { 25 | fn to_string(&self) -> String { 26 | match self { 27 | Self::CreatedAtAsc => String::from("CREATED_AT_ASC"), 28 | Self::CreatedAtDesc => String::from("CREATED_AT_DESC"), 29 | Self::Name => String::from("NAME"), 30 | } 31 | } 32 | } 33 | 34 | impl Default for FetchOrgOrderBy { 35 | fn default() -> FetchOrgOrderBy { 36 | Self::CreatedAtAsc 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/models/invite_user_to_org_request.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 2 | pub struct InviteUserToOrgRequest { 3 | #[serde(rename = "org_id")] 4 | pub org_id: String, 5 | #[serde(rename = "email")] 6 | pub email: String, 7 | #[serde(rename = "role")] 8 | pub role: String, 9 | #[serde(rename = "additional_roles")] 10 | pub additional_roles: Vec, 11 | } 12 | 13 | impl InviteUserToOrgRequest { 14 | pub fn new(org_id: String, email: String, role: String) -> InviteUserToOrgRequest { 15 | InviteUserToOrgRequest { 16 | org_id, 17 | email, 18 | role, 19 | additional_roles: vec![], 20 | } 21 | } 22 | 23 | pub fn with_multiple_roles( 24 | org_id: String, 25 | email: String, 26 | mut roles: Vec, 27 | ) -> Option { 28 | let role = roles.pop()?; 29 | 30 | Some(InviteUserToOrgRequest { 31 | org_id, 32 | email, 33 | role, 34 | additional_roles: roles, 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /docs/UpdateMetadataRequest.md: -------------------------------------------------------------------------------- 1 | # UpdateMetadataRequest 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---------------------------- | ---------------------------------- | ----------- | ---------- | 7 | | **username** | Option<**String**> | | [optional] | 8 | | **first_name** | Option<**String**> | | [optional] | 9 | | **last_name** | Option<**String**> | | [optional] | 10 | | **picture_url** | Option<**String**> | | [optional] | 11 | | **metadata** | Option<**HashMap**> | | [optional] | 12 | | **properties** | Option<**HashMap**> | | [optional] | 13 | | **update_password_required** | Option<**bool**> | | [optional] | 14 | 15 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 16 | -------------------------------------------------------------------------------- /src/models/user_paged_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct UserPagedResponse { 16 | #[serde(rename = "users")] 17 | pub users: Vec, 18 | #[serde(rename = "total_users")] 19 | pub total_users: i64, 20 | #[serde(rename = "current_page")] 21 | pub current_page: i64, 22 | #[serde(rename = "page_size")] 23 | pub page_size: i64, 24 | #[serde(rename = "has_more_results")] 25 | pub has_more_results: bool, 26 | } 27 | 28 | impl UserPagedResponse { 29 | pub fn new(users: Vec, total_users: i64, current_page: i64, page_size: i64, has_more_results: bool) -> UserPagedResponse { 30 | UserPagedResponse { 31 | users, 32 | total_users, 33 | current_page, 34 | page_size, 35 | has_more_results, 36 | } 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/models/fetch_orgs_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct FetchOrgsResponse { 16 | #[serde(rename = "orgs")] 17 | pub orgs: Vec, 18 | #[serde(rename = "total_orgs")] 19 | pub total_orgs: i64, 20 | #[serde(rename = "current_page")] 21 | pub current_page: i64, 22 | #[serde(rename = "page_size")] 23 | pub page_size: i64, 24 | #[serde(rename = "has_more_results")] 25 | pub has_more_results: bool, 26 | } 27 | 28 | impl FetchOrgsResponse { 29 | pub fn new(orgs: Vec, total_orgs: i64, current_page: i64, page_size: i64, has_more_results: bool) -> FetchOrgsResponse { 30 | FetchOrgsResponse { 31 | orgs, 32 | total_orgs, 33 | current_page, 34 | page_size, 35 | has_more_results, 36 | } 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/models/user_in_org.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use serde_json::Value; 12 | use std::collections::HashMap; 13 | 14 | use crate::propelauth::token_models::OrgRoleStructure; 15 | 16 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 17 | pub struct UserInOrg { 18 | #[serde(rename = "org_id")] 19 | pub org_id: String, 20 | #[serde(rename = "org_name")] 21 | pub org_name: String, 22 | #[serde(rename = "org_metadata")] 23 | pub org_metadata: HashMap, 24 | #[serde(rename = "org_role_structure")] 25 | pub org_role_structure: OrgRoleStructure, 26 | #[serde(rename = "user_role")] 27 | pub user_role: String, 28 | #[serde(rename = "inherited_user_roles_plus_current_role")] 29 | pub inherited_user_roles_plus_current_role: Vec, 30 | #[serde(rename = "user_permissions")] 31 | pub user_permissions: Vec, 32 | #[serde(rename = "additional_roles")] 33 | pub additional_roles: Vec, 34 | } 35 | -------------------------------------------------------------------------------- /src/propelauth/options.rs: -------------------------------------------------------------------------------- 1 | use crate::models::AuthTokenVerificationMetadata; 2 | 3 | pub struct AuthOptionsWithTokenVerification { 4 | pub auth_url: String, 5 | pub api_key: String, 6 | 7 | /// By default, this library performs a one-time fetch on startup for 8 | /// token verification metadata from your authUrl using your apiKey. 9 | /// This is usually preferred to make sure you have the most up to date information, 10 | /// however, in environments like serverless, this one-time fetch becomes a 11 | /// per-request fetch. 12 | /// You can specify the token verification metadata manually, 13 | /// which you can obtain from your PropelAuth project. 14 | pub manual_token_verification_metadata: AuthTokenVerificationMetadata, 15 | } 16 | 17 | pub struct AuthOptions { 18 | pub auth_url: String, 19 | pub api_key: String, 20 | } 21 | 22 | #[derive(Debug, Clone, PartialEq)] 23 | pub enum RequiredOrg<'a> { 24 | OrgId(&'a str), 25 | OrgName(&'a str), 26 | } 27 | 28 | #[derive(Debug, Clone, PartialEq)] 29 | pub enum UserRequirementsInOrg<'a> { 30 | None, 31 | IsRole(&'a str), 32 | IsAtLeastRole(&'a str), 33 | HasPermission(&'a str), 34 | HasAllPermissions(Vec<&'a str>), 35 | } 36 | -------------------------------------------------------------------------------- /src/models/bad_update_user_metadata_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadUpdateUserMetadataRequest { 16 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 17 | pub username: Option>, 18 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 19 | pub first_name: Option>, 20 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 21 | pub last_name: Option>, 22 | #[serde(rename = "picture_url", skip_serializing_if = "Option::is_none")] 23 | pub picture_url: Option>, 24 | } 25 | 26 | impl BadUpdateUserMetadataRequest { 27 | pub fn new() -> BadUpdateUserMetadataRequest { 28 | BadUpdateUserMetadataRequest { 29 | username: None, 30 | first_name: None, 31 | last_name: None, 32 | picture_url: None, 33 | } 34 | } 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/models/fetch_pending_invites.rs: -------------------------------------------------------------------------------- 1 | #[derive(Deserialize, Debug)] 2 | pub struct FetchPendingInvitesResponse { 3 | #[serde(rename = "total_invites")] 4 | pub total_invites: i64, 5 | #[serde(rename = "current_page")] 6 | pub current_page: i64, 7 | #[serde(rename = "page_size")] 8 | pub page_size: i64, 9 | #[serde(rename = "has_more_results")] 10 | pub has_more_results: bool, 11 | #[serde(rename = "invites")] 12 | pub invites: Vec, 13 | } 14 | 15 | #[derive(Deserialize, Debug)] 16 | pub struct PendingInviteResponse { 17 | #[serde(rename = "invitee_email")] 18 | pub invitee_email: String, 19 | #[serde(rename = "org_id")] 20 | pub org_id: String, 21 | #[serde(rename = "org_name")] 22 | pub org_name: String, 23 | #[serde(rename = "role_in_org")] 24 | pub role_in_org: String, 25 | #[serde(rename = "additional_roles_in_org")] 26 | pub additional_roles_in_org: Vec, 27 | #[serde(rename = "created_at")] 28 | pub created_at: i64, 29 | #[serde(rename = "expires_at")] 30 | pub expires_at: i64, 31 | #[serde(rename = "inviter_email", default)] 32 | pub inviter_email: Option, 33 | #[serde(rename = "inviter_user_id", default)] 34 | pub inviter_user_id: Option, 35 | } 36 | -------------------------------------------------------------------------------- /src/models/validate_api_key_response.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use serde_json::Value; 3 | use uuid::Uuid; 4 | use crate::models::{UserInOrg, UserMetadata}; 5 | 6 | pub type OrgRole = String; 7 | 8 | #[derive(Clone, Debug, PartialEq, Deserialize)] 9 | pub struct ValidateApiKeyResponse { 10 | pub metadata: Option, 11 | pub user: Option, 12 | pub org: Option, 13 | pub user_in_org: Option, 14 | pub user_id: Option, 15 | pub org_id: Option, 16 | } 17 | 18 | #[derive(Clone, Debug, PartialEq, Deserialize)] 19 | pub struct ValidatePersonalApiKeyResponse { 20 | pub metadata: Option, 21 | pub user: UserMetadata, 22 | } 23 | 24 | #[derive(Clone, Debug, PartialEq, Deserialize)] 25 | pub struct ValidateOrgApiKeyResponse { 26 | pub metadata: Option, 27 | pub user: Option, 28 | pub org: OrgMetadata, 29 | pub user_in_org: Option, 30 | } 31 | 32 | #[derive(Clone, Debug, PartialEq, Deserialize)] 33 | pub struct OrgMetadata { 34 | pub org_id: Uuid, 35 | pub org_name: String, 36 | pub can_setup_saml: bool, 37 | pub max_users: Option, 38 | pub metadata: MetadataHashOfValue, 39 | } 40 | 41 | pub type MetadataHashOfValue = HashMap; 42 | 43 | -------------------------------------------------------------------------------- /src/models/bad_create_magic_link_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadCreateMagicLinkRequest { 16 | #[serde(rename = "email", skip_serializing_if = "Option::is_none")] 17 | pub email: Option>, 18 | #[serde(rename = "redirect_to_url", skip_serializing_if = "Option::is_none")] 19 | pub redirect_to_url: Option>, 20 | #[serde(rename = "expires_in_hours", skip_serializing_if = "Option::is_none")] 21 | pub expires_in_hours: Option>, 22 | #[serde(rename = "create_new_user_if_one_doesnt_exist", skip_serializing_if = "Option::is_none")] 23 | pub create_new_user_if_one_doesnt_exist: Option>, 24 | } 25 | 26 | impl BadCreateMagicLinkRequest { 27 | pub fn new() -> BadCreateMagicLinkRequest { 28 | BadCreateMagicLinkRequest { 29 | email: None, 30 | redirect_to_url: None, 31 | expires_in_hours: None, 32 | create_new_user_if_one_doesnt_exist: None, 33 | } 34 | } 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/models/bad_create_user_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadCreateUserRequest { 16 | #[serde(rename = "email", skip_serializing_if = "Option::is_none")] 17 | pub email: Option>, 18 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 19 | pub username: Option>, 20 | #[serde(rename = "password", skip_serializing_if = "Option::is_none")] 21 | pub password: Option>, 22 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 23 | pub first_name: Option>, 24 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 25 | pub last_name: Option>, 26 | } 27 | 28 | impl BadCreateUserRequest { 29 | pub fn new() -> BadCreateUserRequest { 30 | BadCreateUserRequest { 31 | email: None, 32 | username: None, 33 | password: None, 34 | first_name: None, 35 | last_name: None, 36 | } 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/models/add_user_to_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 12 | pub struct AddUserToOrgRequest { 13 | #[serde(rename = "user_id")] 14 | pub user_id: String, 15 | #[serde(rename = "org_id")] 16 | pub org_id: String, 17 | #[serde(rename = "role")] 18 | pub role: String, 19 | #[serde(rename = "additional_roles")] 20 | pub additional_roles: Vec, 21 | } 22 | 23 | impl AddUserToOrgRequest { 24 | pub fn new(user_id: String, org_id: String, role: String) -> AddUserToOrgRequest { 25 | AddUserToOrgRequest { 26 | user_id, 27 | org_id, 28 | role, 29 | additional_roles: vec![], 30 | } 31 | } 32 | 33 | pub fn with_multiple_roles( 34 | user_id: String, 35 | org_id: String, 36 | mut roles: Vec, 37 | ) -> Option { 38 | let role = roles.pop()?; 39 | 40 | Some(AddUserToOrgRequest { 41 | user_id, 42 | org_id, 43 | role, 44 | additional_roles: roles, 45 | }) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/models/change_user_role_in_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 12 | pub struct ChangeUserRoleInOrgRequest { 13 | #[serde(rename = "user_id")] 14 | pub user_id: String, 15 | #[serde(rename = "org_id")] 16 | pub org_id: String, 17 | #[serde(rename = "role")] 18 | pub role: String, 19 | #[serde(rename = "additional_roles")] 20 | pub additional_roles: Vec, 21 | } 22 | 23 | impl ChangeUserRoleInOrgRequest { 24 | pub fn new(user_id: String, org_id: String, role: String) -> ChangeUserRoleInOrgRequest { 25 | ChangeUserRoleInOrgRequest { 26 | user_id, 27 | org_id, 28 | role, 29 | additional_roles: vec![], 30 | } 31 | } 32 | 33 | pub fn with_multiple_roles( 34 | user_id: String, 35 | org_id: String, 36 | mut roles: Vec, 37 | ) -> Option { 38 | let role = roles.pop()?; 39 | 40 | Some(ChangeUserRoleInOrgRequest { 41 | user_id, 42 | org_id, 43 | role, 44 | additional_roles: roles, 45 | }) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/propelauth/employee.rs: -------------------------------------------------------------------------------- 1 | use crate::apis::configuration::Configuration; 2 | use crate::apis::employee_service_api::{ 3 | FetchEmployeeByIdParams, Employee, 4 | }; 5 | use crate::propelauth::helpers::{is_valid_id, map_autogenerated_error}; 6 | use crate::propelauth::errors::ErrorsWithNotFound; 7 | 8 | pub struct EmployeeService<'a> { 9 | pub(crate) config: &'a Configuration, 10 | } 11 | 12 | impl EmployeeService<'_> { 13 | 14 | pub async fn fetch_employee_by_id( 15 | &self, 16 | params: FetchEmployeeByIdParams, 17 | ) -> Result { 18 | if !is_valid_id(¶ms.employee_id) { 19 | return Err(ErrorsWithNotFound::NotFound); 20 | } 21 | 22 | crate::apis::employee_service_api::fetch_employee_by_id(&self.config, params) 23 | .await 24 | .map_err(|err| { 25 | map_autogenerated_error( 26 | err, 27 | ErrorsWithNotFound::UnexpectedException, 28 | |status_code, _| match status_code.as_u16() { 29 | 401 => ErrorsWithNotFound::InvalidApiKey, 30 | 429 => ErrorsWithNotFound::PropelAuthRateLimit, 31 | 404 => ErrorsWithNotFound::NotFound, 32 | _ => ErrorsWithNotFound::UnexpectedException, 33 | }, 34 | ) 35 | }) 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/models/create_magic_link_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct CreateMagicLinkRequest { 16 | #[serde(rename = "email")] 17 | pub email: String, 18 | #[serde(rename = "redirect_to_url", skip_serializing_if = "Option::is_none")] 19 | pub redirect_to_url: Option, 20 | #[serde(rename = "expires_in_hours", skip_serializing_if = "Option::is_none")] 21 | pub expires_in_hours: Option, 22 | #[serde(rename = "create_new_user_if_one_doesnt_exist", skip_serializing_if = "Option::is_none")] 23 | pub create_new_user_if_one_doesnt_exist: Option, 24 | #[serde(rename = "expire_after_first_use", skip_serializing_if = "Option::is_none")] 25 | pub expire_after_first_use: Option, 26 | } 27 | 28 | impl CreateMagicLinkRequest { 29 | pub fn new(email: String) -> CreateMagicLinkRequest { 30 | CreateMagicLinkRequest { 31 | email, 32 | redirect_to_url: None, 33 | expires_in_hours: None, 34 | create_new_user_if_one_doesnt_exist: None, 35 | expire_after_first_use: None, 36 | } 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/apis/configuration.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use reqwest; 12 | 13 | #[derive(Debug, Clone)] 14 | pub struct Configuration { 15 | pub base_path: String, 16 | pub auth_hostname: String, 17 | pub user_agent: Option, 18 | pub client: reqwest::Client, 19 | pub basic_auth: Option, 20 | pub oauth_access_token: Option, 21 | pub bearer_access_token: Option, 22 | pub api_key: Option, 23 | // TODO: take an oauth2 token source, similar to the go one 24 | } 25 | 26 | pub type BasicAuth = (String, Option); 27 | 28 | #[derive(Debug, Clone)] 29 | pub struct ApiKey { 30 | pub prefix: Option, 31 | pub key: String, 32 | } 33 | 34 | impl Default for Configuration { 35 | fn default() -> Self { 36 | Configuration { 37 | base_path: "http://localhost".to_owned(), 38 | auth_hostname: "http://localhost".to_owned(), 39 | user_agent: Some("OpenAPI-Generator/0.1.0/rust".to_owned()), 40 | client: reqwest::Client::new(), 41 | basic_auth: None, 42 | oauth_access_token: None, 43 | bearer_access_token: None, 44 | api_key: None, 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /docs/AccessTokenServiceApi.md: -------------------------------------------------------------------------------- 1 | # \AccessTokenServiceApi 2 | 3 | All URIs are relative to _http://localhost_ 4 | 5 | | Method | HTTP request | Description | 6 | | ----------------------------------------------------------------------- | ------------------------------------- | ----------- | 7 | | [**create_access_Token**](AccessTokenServiceApi.md#create_access_token) | **POST** /api/backend/v1/access_token | 8 | 9 | ## create_access_Token 10 | 11 | > crate::models::CreateAccessTokenResponse create_access_token(create_access_token_params) 12 | 13 | ### Parameters 14 | 15 | | Name | Type | Description | Notes | 16 | | -------------------------- | -------------------------------------------------------------------------- | ----------- | ----- | 17 | | create_access_token_params | [**crate::models::CreateAccessTokenRequest**](CreateAccessTokenRequest.md) | | | 18 | 19 | ### Return type 20 | 21 | [**crate::models::CreateAccessTokenResponse**](CreateAccessTokenResponse.md) 22 | 23 | ### Authorization 24 | 25 | [BearerAuth](../README.md#BearerAuth) 26 | 27 | ### HTTP request headers 28 | 29 | - **Content-Type**: Not defined 30 | - **Accept**: application/json 31 | 32 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 33 | -------------------------------------------------------------------------------- /src/models/fetch_users_order_by.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | /// 13 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] 14 | pub enum FetchUsersOrderBy { 15 | #[serde(rename = "CREATED_AT_ASC")] 16 | CreatedAtAsc, 17 | #[serde(rename = "CREATED_AT_DESC")] 18 | CreatedAtDesc, 19 | #[serde(rename = "LAST_ACTIVE_AT_ASC")] 20 | LastActiveAtAsc, 21 | #[serde(rename = "LAST_ACTIVE_AT_DESC")] 22 | LastActiveAtDesc, 23 | #[serde(rename = "EMAIL")] 24 | Email, 25 | #[serde(rename = "USERNAME")] 26 | Username, 27 | 28 | } 29 | 30 | impl ToString for FetchUsersOrderBy { 31 | fn to_string(&self) -> String { 32 | match self { 33 | Self::CreatedAtAsc => String::from("CREATED_AT_ASC"), 34 | Self::CreatedAtDesc => String::from("CREATED_AT_DESC"), 35 | Self::LastActiveAtAsc => String::from("LAST_ACTIVE_AT_ASC"), 36 | Self::LastActiveAtDesc => String::from("LAST_ACTIVE_AT_DESC"), 37 | Self::Email => String::from("EMAIL"), 38 | Self::Username => String::from("USERNAME"), 39 | } 40 | } 41 | } 42 | 43 | impl Default for FetchUsersOrderBy { 44 | fn default() -> FetchUsersOrderBy { 45 | Self::CreatedAtAsc 46 | } 47 | } 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "propelauth" 3 | version = "0.23.4" 4 | authors = ["support@propelauth.com"] 5 | description = "A Rust crate for managing authentication and authorization with support for multi-tenant / B2B products, powered by PropelAuth" 6 | keywords = ["authentication", "auth", "authorization", "b2b", "tenant"] 7 | categories = ["authentication"] 8 | homepage = "https://www.propelauth.com" 9 | repository = "https://github.com/PropelAuth/rust/" 10 | license = "MIT" 11 | edition = "2018" 12 | 13 | [dependencies] 14 | actix-web = { version = "4", optional = true } 15 | axum_06 = { package = "axum", version = "^0.6", optional = true } 16 | axum_07 = { package = "axum", version = "^0.7", optional = true } 17 | axum_08 = { package = "axum", version = "^0.8", optional = true } 18 | chrono = "0.4.39" 19 | jsonwebtoken = "9.3.0" 20 | serde = "^1.0" 21 | serde_derive = "^1.0" 22 | serde_json = "^1.0" 23 | thiserror = "^2.0" 24 | tower = { version = "^0.5", optional = true } 25 | url = "^2.2" 26 | uuid = { version = "^1.0", features = ["serde"] } 27 | hex = "0.4.3" 28 | 29 | [dependencies.reqwest] 30 | version = "^0.12" 31 | default-features = false 32 | 33 | [dev-dependencies] 34 | openssl = "0.10.68" 35 | 36 | [features] 37 | default = ["reqwest/default", "__reqwest"] 38 | rustls = ["__reqwest", "reqwest/rustls-tls", "reqwest/http2", "reqwest/charset"] 39 | axum06 = ["dep:axum_06", "dep:tower"] 40 | axum07 = ["dep:axum_07", "dep:tower"] 41 | axum08 = ["dep:axum_08", "dep:tower"] 42 | actix4 = ["dep:actix-web"] 43 | __reqwest = ["reqwest/json", "reqwest/multipart"] 44 | 45 | [lib] 46 | doctest = false 47 | -------------------------------------------------------------------------------- /docs/MigrateUserRequest.md: -------------------------------------------------------------------------------- 1 | # MigrateUserRequest 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | -------------------------------------- | ---------------------------------- | ----------- | ---------- | 7 | | **email** | **String** | | 8 | | **email_confirmed** | **bool** | | 9 | | **existing_user_id** | Option<**String**> | | [optional] | 10 | | **existing_password_hash** | Option<**String**> | | [optional] | 11 | | **existing_mfa_base32_encoded_secret** | Option<**String**> | | [optional] | 12 | | **enabled** | Option<**bool**> | | [optional] | 13 | | **username** | Option<**String**> | | [optional] | 14 | | **first_name** | Option<**String**> | | [optional] | 15 | | **last_name** | Option<**String**> | | [optional] | 16 | | **properties** | Option<**HashMap**> | | [optional] | 17 | | **update_password_required** | Option<**bool**> | | [optional] | 18 | 19 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 20 | -------------------------------------------------------------------------------- /src/models/create_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct CreateOrgRequest { 16 | #[serde(rename = "name")] 17 | pub name: String, 18 | #[serde(rename = "domain", skip_serializing_if = "Option::is_none")] 19 | pub domain: Option, 20 | #[serde(rename = "enable_auto_joining_by_domain", skip_serializing_if = "Option::is_none")] 21 | pub enable_auto_joining_by_domain: Option, 22 | #[serde(rename = "members_must_have_matching_domain", skip_serializing_if = "Option::is_none")] 23 | pub members_must_have_matching_domain: Option, 24 | #[serde(rename = "max_users", skip_serializing_if = "Option::is_none")] 25 | pub max_users: Option, 26 | #[serde(rename = "custom_role_mapping_name", skip_serializing_if = "Option::is_none")] 27 | pub custom_role_mapping_name: Option, 28 | #[serde(rename = "legacy_org_id", skip_serializing_if = "Option::is_none")] 29 | pub legacy_org_id: Option, 30 | } 31 | 32 | impl CreateOrgRequest { 33 | pub fn new(name: String) -> CreateOrgRequest { 34 | CreateOrgRequest { 35 | name, 36 | domain: None, 37 | enable_auto_joining_by_domain: None, 38 | members_must_have_matching_domain: None, 39 | max_users: None, 40 | custom_role_mapping_name: None, 41 | legacy_org_id: None, 42 | } 43 | } 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/models/bad_migrate_user_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct BadMigrateUserRequest { 16 | #[serde(rename = "email", skip_serializing_if = "Option::is_none")] 17 | pub email: Option>, 18 | #[serde(rename = "existing_user_id", skip_serializing_if = "Option::is_none")] 19 | pub existing_user_id: Option>, 20 | #[serde(rename = "existing_password_hash", skip_serializing_if = "Option::is_none")] 21 | pub existing_password_hash: Option>, 22 | #[serde(rename = "existing_mfa_base32_encoded_secret", skip_serializing_if = "Option::is_none")] 23 | pub existing_mfa_base32_encoded_secret: Option>, 24 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 25 | pub username: Option>, 26 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 27 | pub first_name: Option>, 28 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 29 | pub last_name: Option>, 30 | } 31 | 32 | impl BadMigrateUserRequest { 33 | pub fn new() -> BadMigrateUserRequest { 34 | BadMigrateUserRequest { 35 | email: None, 36 | existing_user_id: None, 37 | existing_password_hash: None, 38 | existing_mfa_base32_encoded_secret: None, 39 | username: None, 40 | first_name: None, 41 | last_name: None, 42 | } 43 | } 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/models/update_metadata_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | 12 | 13 | 14 | use std::collections::HashMap; 15 | 16 | use serde_json::Value; 17 | 18 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 19 | pub struct UpdateMetadataRequest { 20 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 21 | pub username: Option, 22 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 23 | pub first_name: Option, 24 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 25 | pub last_name: Option, 26 | #[serde(rename = "picture_url", skip_serializing_if = "Option::is_none")] 27 | pub picture_url: Option, 28 | #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] 29 | pub metadata: Option>, 30 | #[serde(rename = "properties", skip_serializing_if = "Option::is_none")] 31 | pub properties: Option>, 32 | #[serde(rename = "update_password_required", skip_serializing_if = "Option::is_none")] 33 | pub update_password_required: Option, 34 | #[serde(rename = "legacy_user_id", skip_serializing_if = "Option::is_none")] 35 | pub legacy_user_id: Option, 36 | } 37 | 38 | impl UpdateMetadataRequest { 39 | pub fn new() -> UpdateMetadataRequest { 40 | UpdateMetadataRequest { 41 | username: None, 42 | first_name: None, 43 | last_name: None, 44 | picture_url: None, 45 | metadata: None, 46 | properties: None, 47 | update_password_required: None, 48 | legacy_user_id: None, 49 | } 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/models/create_user_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use serde_json::Value; 12 | use std::collections::HashMap; 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct CreateUserRequest { 16 | #[serde(rename = "email")] 17 | pub email: String, 18 | #[serde(rename = "email_confirmed")] 19 | pub email_confirmed: bool, 20 | #[serde(rename = "send_email_to_confirm_email_address")] 21 | pub send_email_to_confirm_email_address: bool, 22 | #[serde(rename = "password", skip_serializing_if = "Option::is_none")] 23 | pub password: Option, 24 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 25 | pub username: Option, 26 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 27 | pub first_name: Option, 28 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 29 | pub last_name: Option, 30 | #[serde(rename = "properties", skip_serializing_if = "Option::is_none")] 31 | pub properties: Option>, 32 | #[serde( 33 | rename = "ignore_domain_restrictions", 34 | skip_serializing_if = "Option::is_none" 35 | )] 36 | pub ignore_domain_restrictions: Option, 37 | } 38 | 39 | impl CreateUserRequest { 40 | pub fn new( 41 | email: String, 42 | email_confirmed: bool, 43 | send_email_to_confirm_email_address: bool, 44 | ) -> CreateUserRequest { 45 | CreateUserRequest { 46 | email, 47 | email_confirmed, 48 | send_email_to_confirm_email_address, 49 | password: None, 50 | username: None, 51 | first_name: None, 52 | last_name: None, 53 | properties: None, 54 | ignore_domain_restrictions: None, 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/models/update_org_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use std::collections::HashMap; 12 | 13 | use serde_json::Value; 14 | 15 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 16 | pub struct UpdateOrgRequest { 17 | #[serde(rename = "name", skip_serializing_if = "Option::is_none")] 18 | pub name: Option, 19 | #[serde(rename = "can_setup_saml", skip_serializing_if = "Option::is_none")] 20 | pub can_setup_saml: Option, 21 | #[serde(rename = "max_users", skip_serializing_if = "Option::is_none")] 22 | pub max_users: Option, 23 | #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] 24 | pub metadata: Option>, 25 | #[serde(rename = "domain", skip_serializing_if = "Option::is_none")] 26 | pub domain: Option, 27 | #[serde(rename = "autojoin_by_domain", skip_serializing_if = "Option::is_none")] 28 | pub autojoin_by_domain: Option, 29 | #[serde(rename = "restrict_to_domain", skip_serializing_if = "Option::is_none")] 30 | pub restrict_to_domain: Option, 31 | #[serde(rename = "legacy_org_id", skip_serializing_if = "Option::is_none")] 32 | pub legacy_org_id: Option, 33 | #[serde(rename = "require_2fa_by", skip_serializing_if = "Option::is_none")] 34 | pub require_2fa_by: Option, 35 | #[serde(rename = "extra_domains", skip_serializing_if = "Option::is_none")] 36 | pub extra_domains: Option>, 37 | } 38 | 39 | impl UpdateOrgRequest { 40 | pub fn new() -> UpdateOrgRequest { 41 | UpdateOrgRequest { 42 | name: None, 43 | can_setup_saml: None, 44 | max_users: None, 45 | metadata: None, 46 | domain: None, 47 | autojoin_by_domain: None, 48 | restrict_to_domain: None, 49 | legacy_org_id: None, 50 | require_2fa_by: None, 51 | extra_domains: None, 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/actix/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::propelauth::auth::PropelAuth; 2 | use crate::propelauth::errors::{UnauthorizedError, UnauthorizedOrForbiddenError}; 3 | use crate::propelauth::token_models::User; 4 | use actix_web::dev::Payload; 5 | use actix_web::error::{ErrorInternalServerError, ErrorUnauthorized}; 6 | use actix_web::http::header::AUTHORIZATION; 7 | use actix_web::{web, FromRequest, HttpRequest, HttpResponse, ResponseError}; 8 | use std::future::{ready, Ready}; 9 | 10 | impl FromRequest for User { 11 | type Error = actix_web::error::Error; 12 | type Future = Ready>; 13 | 14 | fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future { 15 | let auth_header_opt = req 16 | .headers() 17 | .get(AUTHORIZATION) 18 | .and_then(|header| header.to_str().ok()); 19 | 20 | let auth_header = match auth_header_opt { 21 | Some(auth_header) => auth_header, 22 | None => return ready(Err(ErrorUnauthorized("Unauthorized"))), 23 | }; 24 | 25 | let auth_opt = req.app_data::>(); 26 | let auth = match auth_opt { 27 | Some(auth) => auth, 28 | None => return ready(Err(ErrorInternalServerError("No app_data found"))), 29 | }; 30 | 31 | ready( 32 | match auth.verify().validate_authorization_header(auth_header) { 33 | Ok(user) => Ok(user), 34 | Err(UnauthorizedError::Unauthorized(_)) => Err(ErrorUnauthorized("Unauthorized")), 35 | }, 36 | ) 37 | } 38 | } 39 | 40 | impl ResponseError for UnauthorizedError { 41 | fn error_response(&self) -> HttpResponse { 42 | match self { 43 | UnauthorizedError::Unauthorized(_) => HttpResponse::Unauthorized().body("Unauthorized"), 44 | } 45 | } 46 | } 47 | 48 | impl ResponseError for UnauthorizedOrForbiddenError { 49 | fn error_response(&self) -> HttpResponse { 50 | match self { 51 | UnauthorizedOrForbiddenError::Unauthorized(_) => { 52 | HttpResponse::Unauthorized().body("Unauthorized") 53 | } 54 | UnauthorizedOrForbiddenError::Forbidden(_) => { 55 | HttpResponse::Forbidden().body("Forbidden") 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/apis/mod.rs: -------------------------------------------------------------------------------- 1 | use std::error; 2 | use std::fmt; 3 | 4 | #[derive(Debug, Clone)] 5 | pub struct ResponseContent { 6 | pub status: reqwest::StatusCode, 7 | pub content: String, 8 | pub entity: Option, 9 | } 10 | 11 | #[derive(Debug)] 12 | pub enum Error { 13 | Reqwest(reqwest::Error), 14 | Serde(serde_json::Error), 15 | Io(std::io::Error), 16 | Params(String), 17 | ResponseError(ResponseContent), 18 | } 19 | 20 | #[derive(Debug, Serialize, Clone, Deserialize)] 21 | pub struct UserFacingError { 22 | pub user_facing_error: String, 23 | } 24 | 25 | impl fmt::Display for Error { 26 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 27 | let (module, e) = match self { 28 | Error::Reqwest(e) => ("reqwest", e.to_string()), 29 | Error::Serde(e) => ("serde", e.to_string()), 30 | Error::Io(e) => ("IO", e.to_string()), 31 | Error::Params(e) => ("params", e.to_string()), 32 | Error::ResponseError(e) => ("response", format!("status code {}", e.status)), 33 | }; 34 | write!(f, "error in {}: {}", module, e) 35 | } 36 | } 37 | 38 | impl error::Error for Error { 39 | fn source(&self) -> Option<&(dyn error::Error + 'static)> { 40 | Some(match self { 41 | Error::Reqwest(e) => e, 42 | Error::Serde(e) => e, 43 | Error::Io(e) => e, 44 | Error::Params(_) => return None, 45 | Error::ResponseError(_) => return None, 46 | }) 47 | } 48 | } 49 | 50 | impl From for Error { 51 | fn from(e: reqwest::Error) -> Self { 52 | Error::Reqwest(e) 53 | } 54 | } 55 | 56 | impl From for Error { 57 | fn from(e: serde_json::Error) -> Self { 58 | Error::Serde(e) 59 | } 60 | } 61 | 62 | impl From for Error { 63 | fn from(e: std::io::Error) -> Self { 64 | Error::Io(e) 65 | } 66 | } 67 | 68 | pub fn urlencode>(s: T) -> String { 69 | ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() 70 | } 71 | 72 | pub mod access_token_service_api; 73 | pub mod api_key_service_api; 74 | pub mod auth_service_api; 75 | pub mod org_service_api; 76 | pub mod user_service_api; 77 | pub mod employee_service_api; 78 | pub mod mfa_service_api; 79 | 80 | pub mod configuration; 81 | -------------------------------------------------------------------------------- /src/models/migrate_user_request.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use serde_json::Value; 12 | use std::collections::HashMap; 13 | 14 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 15 | pub struct MigrateUserRequest { 16 | #[serde(rename = "email")] 17 | pub email: String, 18 | #[serde(rename = "email_confirmed")] 19 | pub email_confirmed: bool, 20 | #[serde(rename = "existing_user_id", skip_serializing_if = "Option::is_none")] 21 | pub existing_user_id: Option, 22 | #[serde( 23 | rename = "existing_password_hash", 24 | skip_serializing_if = "Option::is_none" 25 | )] 26 | pub existing_password_hash: Option, 27 | #[serde( 28 | rename = "existing_mfa_base32_encoded_secret", 29 | skip_serializing_if = "Option::is_none" 30 | )] 31 | pub existing_mfa_base32_encoded_secret: Option, 32 | #[serde(rename = "enabled", skip_serializing_if = "Option::is_none")] 33 | pub enabled: Option, 34 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 35 | pub username: Option, 36 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 37 | pub first_name: Option, 38 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 39 | pub last_name: Option, 40 | #[serde(rename = "picture_url", skip_serializing_if = "Option::is_none")] 41 | pub picture_url: Option, 42 | #[serde(rename = "properties", skip_serializing_if = "Option::is_none")] 43 | pub properties: Option>, 44 | #[serde( 45 | rename = "update_password_required", 46 | skip_serializing_if = "Option::is_none" 47 | )] 48 | pub update_password_required: Option, 49 | } 50 | 51 | impl MigrateUserRequest { 52 | pub fn new(email: String, email_confirmed: bool) -> MigrateUserRequest { 53 | MigrateUserRequest { 54 | email, 55 | email_confirmed, 56 | existing_user_id: None, 57 | existing_password_hash: None, 58 | existing_mfa_base32_encoded_secret: None, 59 | enabled: None, 60 | username: None, 61 | first_name: None, 62 | last_name: None, 63 | picture_url: None, 64 | properties: None, 65 | update_password_required: None, 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/apis/auth_service_api.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use reqwest; 12 | 13 | use super::{configuration, Error}; 14 | use crate::{apis::ResponseContent, propelauth::auth::AUTH_HOSTNAME_HEADER}; 15 | 16 | /// struct for typed errors of method [`token_verification_metadata`] 17 | #[derive(Debug, Clone, Serialize, Deserialize)] 18 | #[serde(untagged)] 19 | pub enum TokenVerificationMetadataError { 20 | Status401(serde_json::Value), 21 | UnknownValue(serde_json::Value), 22 | } 23 | 24 | pub async fn token_verification_metadata( 25 | configuration: &configuration::Configuration, 26 | ) -> Result> { 27 | let local_var_configuration = configuration; 28 | 29 | // unbox the parameters 30 | 31 | let local_var_client = &local_var_configuration.client; 32 | 33 | let local_var_uri_str = format!( 34 | "{}/api/backend/v1/token_verification_metadata", 35 | local_var_configuration.base_path 36 | ); 37 | let mut local_var_req_builder = 38 | local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 39 | 40 | if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 41 | local_var_req_builder = 42 | local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 43 | } 44 | if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 45 | local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 46 | }; 47 | local_var_req_builder = local_var_req_builder.header( 48 | AUTH_HOSTNAME_HEADER, 49 | local_var_configuration.auth_hostname.to_owned(), 50 | ); 51 | 52 | let local_var_req = local_var_req_builder.build()?; 53 | let local_var_resp = local_var_client.execute(local_var_req).await?; 54 | 55 | let local_var_status = local_var_resp.status(); 56 | let local_var_content = local_var_resp.text().await?; 57 | 58 | if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 59 | serde_json::from_str(&local_var_content).map_err(Error::from) 60 | } else { 61 | let local_var_entity: Option = 62 | serde_json::from_str(&local_var_content).ok(); 63 | let local_var_error = ResponseContent { 64 | status: local_var_status, 65 | content: local_var_content, 66 | entity: local_var_entity, 67 | }; 68 | Err(Error::ResponseError(local_var_error)) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/apis/employee_service_api.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use reqwest; 12 | 13 | use super::{configuration, Error}; 14 | use crate::propelauth::auth::AUTH_HOSTNAME_HEADER; 15 | use crate::apis::ResponseContent; 16 | 17 | /// struct for passing parameters to the method [`fetch_employee_by_id`] 18 | #[derive(Clone, Debug, Default)] 19 | pub struct FetchEmployeeByIdParams { 20 | pub employee_id: String, 21 | } 22 | 23 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 24 | pub struct Employee { 25 | #[serde(rename = "email")] 26 | pub email: String, 27 | } 28 | 29 | /// struct for typed errors of method [`fetch_employee_by_id`] 30 | #[derive(Debug, Clone, Serialize, Deserialize)] 31 | #[serde(untagged)] 32 | pub enum FetchEmployeeByIdError { 33 | Status401(serde_json::Value), 34 | Status404(serde_json::Value), 35 | UnknownValue(serde_json::Value), 36 | } 37 | 38 | 39 | pub async fn fetch_employee_by_id( 40 | configuration: &configuration::Configuration, 41 | params: FetchEmployeeByIdParams, 42 | ) -> Result> { 43 | let local_var_configuration = configuration; 44 | 45 | // unbox the parameters 46 | let employee_id = params.employee_id; 47 | 48 | let local_var_client = &local_var_configuration.client; 49 | 50 | let local_var_uri_str = format!( 51 | "{}/api/backend/v1/employee/{employee_id}", 52 | local_var_configuration.base_path, 53 | employee_id = crate::apis::urlencode(employee_id) 54 | ); 55 | let mut local_var_req_builder = 56 | local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); 57 | 58 | if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 59 | local_var_req_builder = 60 | local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 61 | } 62 | if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 63 | local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 64 | }; 65 | local_var_req_builder = local_var_req_builder.header( 66 | AUTH_HOSTNAME_HEADER, 67 | local_var_configuration.auth_hostname.to_owned(), 68 | ); 69 | 70 | let local_var_req = local_var_req_builder.build()?; 71 | let local_var_resp = local_var_client.execute(local_var_req).await?; 72 | 73 | let local_var_status = local_var_resp.status(); 74 | let local_var_content = local_var_resp.text().await?; 75 | 76 | if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 77 | serde_json::from_str(&local_var_content).map_err(Error::from) 78 | } else { 79 | let local_var_entity: Option = 80 | serde_json::from_str(&local_var_content).ok(); 81 | let local_var_error: crate::apis::ResponseContent = ResponseContent { 82 | status: local_var_status, 83 | content: local_var_content, 84 | entity: local_var_entity, 85 | }; 86 | Err(Error::ResponseError(local_var_error)) 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/propelauth/access_token.rs: -------------------------------------------------------------------------------- 1 | use crate::apis::access_token_service_api::{CreateAccessTokenParams, CreateAccessTokenV2Params}; 2 | use crate::apis::configuration::Configuration; 3 | 4 | use crate::models::CreateAccessTokenResponse; 5 | use crate::propelauth::errors::CreateAccessTokenError; 6 | use crate::propelauth::helpers::{is_valid_id, map_autogenerated_error}; 7 | 8 | pub struct AccessTokenService<'a> { 9 | pub(crate) config: &'a Configuration, 10 | } 11 | 12 | impl AccessTokenService<'_> { 13 | pub async fn create_access_token( 14 | &self, 15 | params: CreateAccessTokenParams, 16 | ) -> Result { 17 | if !is_valid_id(¶ms.create_access_token_request.user_id) { 18 | return Err(CreateAccessTokenError::NotFound); 19 | } 20 | 21 | crate::apis::access_token_service_api::create_access_token(&self.config, params) 22 | .await 23 | .map_err(|err| { 24 | map_autogenerated_error( 25 | err, 26 | CreateAccessTokenError::UnexpectedException, 27 | |status_code, err_entity| match (status_code.as_u16(), err_entity) { 28 | ( 29 | _, 30 | Some(crate::apis::access_token_service_api::CreateAccessTokenError::Status400( 31 | bad_request, 32 | )), 33 | ) => CreateAccessTokenError::BadRequest(bad_request), 34 | (401, _) => CreateAccessTokenError::InvalidApiKey, 35 | (429, _) => CreateAccessTokenError::PropelAuthRateLimit, 36 | (404, _) => CreateAccessTokenError::NotFound, 37 | _ => CreateAccessTokenError::UnexpectedException, 38 | }, 39 | ) 40 | }) 41 | } 42 | 43 | pub async fn create_access_token_v2( 44 | &self, 45 | params: CreateAccessTokenV2Params, 46 | ) -> Result { 47 | if !is_valid_id(¶ms.create_access_token_request.user_id) { 48 | return Err(CreateAccessTokenError::NotFound); 49 | } 50 | 51 | crate::apis::access_token_service_api::create_access_token_v2(&self.config, params) 52 | .await 53 | .map_err(|err| { 54 | map_autogenerated_error( 55 | err, 56 | CreateAccessTokenError::UnexpectedException, 57 | |status_code, err_entity| match (status_code.as_u16(), err_entity) { 58 | ( 59 | _, 60 | Some(crate::apis::access_token_service_api::CreateAccessTokenError::Status400( 61 | bad_request, 62 | )), 63 | ) => CreateAccessTokenError::BadRequest(bad_request), 64 | (401, _) => CreateAccessTokenError::InvalidApiKey, 65 | (429, _) => CreateAccessTokenError::PropelAuthRateLimit, 66 | (404, _) => CreateAccessTokenError::NotFound, 67 | _ => CreateAccessTokenError::UnexpectedException, 68 | }, 69 | ) 70 | }) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/models/user_metadata.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use std::collections::HashMap; 12 | 13 | use serde_json::Value; 14 | 15 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 16 | pub struct UserMetadata { 17 | #[serde(rename = "user_id")] 18 | pub user_id: String, 19 | #[serde(rename = "email")] 20 | pub email: String, 21 | #[serde(rename = "email_confirmed")] 22 | pub email_confirmed: bool, 23 | #[serde(rename = "has_password")] 24 | pub has_password: bool, 25 | #[serde(rename = "username", skip_serializing_if = "Option::is_none")] 26 | pub username: Option, 27 | #[serde(rename = "first_name", skip_serializing_if = "Option::is_none")] 28 | pub first_name: Option, 29 | #[serde(rename = "last_name", skip_serializing_if = "Option::is_none")] 30 | pub last_name: Option, 31 | #[serde(rename = "picture_url", skip_serializing_if = "Option::is_none")] 32 | pub picture_url: Option, 33 | #[serde(rename = "locked")] 34 | pub locked: bool, 35 | #[serde(rename = "enabled")] 36 | pub enabled: bool, 37 | #[serde(rename = "mfa_enabled")] 38 | pub mfa_enabled: bool, 39 | #[serde(rename = "created_at")] 40 | pub created_at: i64, 41 | #[serde(rename = "last_active_at")] 42 | pub last_active_at: i64, 43 | #[serde(rename = "org_id_to_org_info", skip_serializing_if = "Option::is_none")] 44 | pub org_id_to_org_info: Option>, 45 | #[serde(rename = "legacy_user_id", skip_serializing_if = "Option::is_none")] 46 | pub legacy_user_id: Option, 47 | #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] 48 | pub metadata: Option>, 49 | #[serde(rename = "properties", skip_serializing_if = "Option::is_none")] 50 | pub properties: Option>, 51 | /// `role_in_org` is only returned when using `fetch_users_in_org` 52 | /// and is their role for the org specified in the query. 53 | #[serde(rename = "role_in_org", default)] 54 | pub role_in_org: Option, 55 | /// `additional_roles_in_org` is only returned when using `fetch_users_in_org` 56 | /// and is their additional roles for the org specified in the query. 57 | #[serde(rename = "additional_roles_in_org", default)] 58 | pub additional_roles_in_org: Option>, 59 | } 60 | 61 | impl UserMetadata { 62 | pub fn new( 63 | user_id: String, 64 | email: String, 65 | email_confirmed: bool, 66 | has_password: bool, 67 | locked: bool, 68 | enabled: bool, 69 | mfa_enabled: bool, 70 | created_at: i64, 71 | last_active_at: i64, 72 | ) -> UserMetadata { 73 | UserMetadata { 74 | user_id, 75 | email, 76 | email_confirmed, 77 | has_password, 78 | username: None, 79 | first_name: None, 80 | last_name: None, 81 | picture_url: None, 82 | locked, 83 | enabled, 84 | mfa_enabled, 85 | created_at, 86 | last_active_at, 87 | org_id_to_org_info: None, 88 | legacy_user_id: None, 89 | metadata: None, 90 | properties: None, 91 | role_in_org: None, 92 | additional_roles_in_org: None, 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/axum08/mod.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | use std::pin::Pin; 3 | use std::sync::Arc; 4 | use std::task::{Context, Poll}; 5 | 6 | use axum_08::extract::FromRequestParts; 7 | use axum_08::http::header::AUTHORIZATION; 8 | use axum_08::http::request::Parts; 9 | use axum_08::http::StatusCode; 10 | use axum_08::response::IntoResponse; 11 | use axum_08::{body::Body, http::Request, response::Response}; 12 | use tower::{Layer, Service}; 13 | 14 | use crate::propelauth::auth::PropelAuth; 15 | use crate::propelauth::errors::{UnauthorizedError, UnauthorizedOrForbiddenError}; 16 | use crate::propelauth::token_models::User; 17 | 18 | impl FromRequestParts for User 19 | where 20 | S: Send + Sync, 21 | { 22 | type Rejection = (StatusCode, &'static str); 23 | 24 | async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { 25 | let auth_header = parts 26 | .headers 27 | .get(AUTHORIZATION) 28 | .and_then(|header| header.to_str().ok()) 29 | .ok_or((StatusCode::UNAUTHORIZED, "Unauthorized"))?; 30 | 31 | let auth = parts 32 | .extensions 33 | .get::>() 34 | .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "No layer found"))?; 35 | 36 | match auth.verify().validate_authorization_header(auth_header) { 37 | Ok(user) => Ok(user), 38 | Err(UnauthorizedError::Unauthorized(_)) => { 39 | Err((StatusCode::UNAUTHORIZED, "Unauthorized")) 40 | } 41 | } 42 | } 43 | } 44 | 45 | #[derive(Clone)] 46 | pub struct PropelAuthLayer { 47 | auth: Arc, 48 | } 49 | 50 | impl PropelAuthLayer { 51 | pub fn new(auth: PropelAuth) -> PropelAuthLayer { 52 | PropelAuthLayer { 53 | auth: Arc::new(auth), 54 | } 55 | } 56 | } 57 | 58 | impl Layer for PropelAuthLayer { 59 | type Service = PropelAuthMiddleware; 60 | 61 | fn layer(&self, inner: S) -> Self::Service { 62 | PropelAuthMiddleware { 63 | inner, 64 | auth: self.auth.clone(), 65 | } 66 | } 67 | } 68 | 69 | #[derive(Clone)] 70 | pub struct PropelAuthMiddleware { 71 | inner: S, 72 | auth: Arc, 73 | } 74 | 75 | impl Service> for PropelAuthMiddleware 76 | where 77 | S: Service, Response = Response> + Send + 'static, 78 | S::Future: Send + 'static, 79 | { 80 | type Response = S::Response; 81 | type Error = S::Error; 82 | type Future = 83 | Pin> + Send + 'static>>; 84 | 85 | fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { 86 | self.inner.poll_ready(cx) 87 | } 88 | 89 | fn call(&mut self, mut request: Request) -> Self::Future { 90 | request.extensions_mut().insert(self.auth.clone()); 91 | let future = self.inner.call(request); 92 | Box::pin(async move { 93 | let response: Response = future.await?; 94 | Ok(response) 95 | }) 96 | } 97 | } 98 | 99 | impl IntoResponse for UnauthorizedError { 100 | fn into_response(self) -> Response { 101 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 102 | } 103 | } 104 | 105 | impl IntoResponse for UnauthorizedOrForbiddenError { 106 | fn into_response(self) -> Response { 107 | match self { 108 | UnauthorizedOrForbiddenError::Unauthorized(_) => { 109 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 110 | } 111 | UnauthorizedOrForbiddenError::Forbidden(_) => { 112 | (StatusCode::FORBIDDEN, "Forbidden").into_response() 113 | } 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/axum06/mod.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | use std::pin::Pin; 3 | use std::sync::Arc; 4 | use std::task::{Context, Poll}; 5 | 6 | use axum_06::{body::Body, http::Request, response::Response}; 7 | use axum_06::async_trait; 8 | use axum_06::extract::FromRequestParts; 9 | use axum_06::http::header::AUTHORIZATION; 10 | use axum_06::http::request::Parts; 11 | use axum_06::http::StatusCode; 12 | use axum_06::response::IntoResponse; 13 | use tower::{Layer, Service}; 14 | 15 | use crate::propelauth::auth::PropelAuth; 16 | use crate::propelauth::errors::{UnauthorizedError, UnauthorizedOrForbiddenError}; 17 | use crate::propelauth::token_models::User; 18 | 19 | #[async_trait] 20 | impl FromRequestParts for User 21 | where 22 | S: Send + Sync, 23 | { 24 | type Rejection = (StatusCode, &'static str); 25 | 26 | async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { 27 | let auth_header = parts 28 | .headers 29 | .get(AUTHORIZATION) 30 | .and_then(|header| header.to_str().ok()) 31 | .ok_or((StatusCode::UNAUTHORIZED, "Unauthorized"))?; 32 | 33 | let auth = parts 34 | .extensions 35 | .get::>() 36 | .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "No layer found"))?; 37 | 38 | match auth.verify().validate_authorization_header(auth_header) { 39 | Ok(user) => Ok(user), 40 | Err(UnauthorizedError::Unauthorized(_)) => { 41 | Err((StatusCode::UNAUTHORIZED, "Unauthorized")) 42 | } 43 | } 44 | } 45 | } 46 | 47 | #[derive(Clone)] 48 | pub struct PropelAuthLayer { 49 | auth: Arc, 50 | } 51 | 52 | impl PropelAuthLayer { 53 | pub fn new(auth: PropelAuth) -> PropelAuthLayer { 54 | PropelAuthLayer { 55 | auth: Arc::new(auth), 56 | } 57 | } 58 | } 59 | 60 | impl Layer for PropelAuthLayer { 61 | type Service = PropelAuthMiddleware; 62 | 63 | fn layer(&self, inner: S) -> Self::Service { 64 | PropelAuthMiddleware { 65 | inner, 66 | auth: self.auth.clone(), 67 | } 68 | } 69 | } 70 | 71 | #[derive(Clone)] 72 | pub struct PropelAuthMiddleware { 73 | inner: S, 74 | auth: Arc, 75 | } 76 | 77 | impl Service> for PropelAuthMiddleware 78 | where 79 | S: Service, Response = Response> + Send + 'static, 80 | S::Future: Send + 'static, 81 | { 82 | type Response = S::Response; 83 | type Error = S::Error; 84 | type Future = 85 | Pin> + Send + 'static>>; 86 | 87 | fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { 88 | self.inner.poll_ready(cx) 89 | } 90 | 91 | fn call(&mut self, mut request: Request) -> Self::Future { 92 | request.extensions_mut().insert(self.auth.clone()); 93 | let future = self.inner.call(request); 94 | Box::pin(async move { 95 | let response: Response = future.await?; 96 | Ok(response) 97 | }) 98 | } 99 | } 100 | 101 | impl IntoResponse for UnauthorizedError { 102 | fn into_response(self) -> Response { 103 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 104 | } 105 | } 106 | 107 | impl IntoResponse for UnauthorizedOrForbiddenError { 108 | fn into_response(self) -> Response { 109 | match self { 110 | UnauthorizedOrForbiddenError::Unauthorized(_) => { 111 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 112 | } 113 | UnauthorizedOrForbiddenError::Forbidden(_) => { 114 | (StatusCode::FORBIDDEN, "Forbidden").into_response() 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/axum07/mod.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | use std::pin::Pin; 3 | use std::sync::Arc; 4 | use std::task::{Context, Poll}; 5 | 6 | use axum_07::async_trait; 7 | use axum_07::extract::FromRequestParts; 8 | use axum_07::http::header::AUTHORIZATION; 9 | use axum_07::http::request::Parts; 10 | use axum_07::http::StatusCode; 11 | use axum_07::response::IntoResponse; 12 | use axum_07::{body::Body, http::Request, response::Response}; 13 | use tower::{Layer, Service}; 14 | 15 | use crate::propelauth::auth::PropelAuth; 16 | use crate::propelauth::errors::{UnauthorizedError, UnauthorizedOrForbiddenError}; 17 | use crate::propelauth::token_models::User; 18 | 19 | #[async_trait] 20 | impl FromRequestParts for User 21 | where 22 | S: Send + Sync, 23 | { 24 | type Rejection = (StatusCode, &'static str); 25 | 26 | async fn from_request_parts(parts: &mut Parts, _: &S) -> Result { 27 | let auth_header = parts 28 | .headers 29 | .get(AUTHORIZATION) 30 | .and_then(|header| header.to_str().ok()) 31 | .ok_or((StatusCode::UNAUTHORIZED, "Unauthorized"))?; 32 | 33 | let auth = parts 34 | .extensions 35 | .get::>() 36 | .ok_or((StatusCode::INTERNAL_SERVER_ERROR, "No layer found"))?; 37 | 38 | match auth.verify().validate_authorization_header(auth_header) { 39 | Ok(user) => Ok(user), 40 | Err(UnauthorizedError::Unauthorized(_)) => { 41 | Err((StatusCode::UNAUTHORIZED, "Unauthorized")) 42 | } 43 | } 44 | } 45 | } 46 | 47 | #[derive(Clone)] 48 | pub struct PropelAuthLayer { 49 | auth: Arc, 50 | } 51 | 52 | impl PropelAuthLayer { 53 | pub fn new(auth: PropelAuth) -> PropelAuthLayer { 54 | PropelAuthLayer { 55 | auth: Arc::new(auth), 56 | } 57 | } 58 | } 59 | 60 | impl Layer for PropelAuthLayer { 61 | type Service = PropelAuthMiddleware; 62 | 63 | fn layer(&self, inner: S) -> Self::Service { 64 | PropelAuthMiddleware { 65 | inner, 66 | auth: self.auth.clone(), 67 | } 68 | } 69 | } 70 | 71 | #[derive(Clone)] 72 | pub struct PropelAuthMiddleware { 73 | inner: S, 74 | auth: Arc, 75 | } 76 | 77 | impl Service> for PropelAuthMiddleware 78 | where 79 | S: Service, Response = Response> + Send + 'static, 80 | S::Future: Send + 'static, 81 | { 82 | type Response = S::Response; 83 | type Error = S::Error; 84 | type Future = 85 | Pin> + Send + 'static>>; 86 | 87 | fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { 88 | self.inner.poll_ready(cx) 89 | } 90 | 91 | fn call(&mut self, mut request: Request) -> Self::Future { 92 | request.extensions_mut().insert(self.auth.clone()); 93 | let future = self.inner.call(request); 94 | Box::pin(async move { 95 | let response: Response = future.await?; 96 | Ok(response) 97 | }) 98 | } 99 | } 100 | 101 | impl IntoResponse for UnauthorizedError { 102 | fn into_response(self) -> Response { 103 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 104 | } 105 | } 106 | 107 | impl IntoResponse for UnauthorizedOrForbiddenError { 108 | fn into_response(self) -> Response { 109 | match self { 110 | UnauthorizedOrForbiddenError::Unauthorized(_) => { 111 | (StatusCode::UNAUTHORIZED, "Unauthorized").into_response() 112 | } 113 | UnauthorizedOrForbiddenError::Forbidden(_) => { 114 | (StatusCode::FORBIDDEN, "Forbidden").into_response() 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/models/fetch_org_response.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use std::collections::HashMap; 12 | 13 | use serde_json::Value; 14 | 15 | #[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] 16 | pub struct OrgMetadata { 17 | #[serde(flatten)] 18 | pub metadata: HashMap, 19 | } 20 | 21 | impl OrgMetadata { 22 | pub fn is_empty(&self) -> bool { 23 | self.metadata.is_empty() 24 | } 25 | } 26 | 27 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 28 | pub struct FetchOrgResponse { 29 | pub org_id: String, 30 | pub name: String, 31 | pub is_saml_configured: bool, 32 | #[serde(default, skip_serializing_if = "OrgMetadata::is_empty")] 33 | pub metadata: OrgMetadata, 34 | #[serde(default, skip_serializing_if = "Option::is_none")] 35 | pub max_users: Option, 36 | #[serde(default, skip_serializing_if = "Option::is_none")] 37 | pub custom_role_mapping_name: Option, 38 | #[serde(default, skip_serializing_if = "Option::is_none")] 39 | pub legacy_org_id: Option, 40 | pub url_safe_org_slug: String, 41 | pub can_setup_saml: bool, 42 | pub is_saml_in_test_mode: bool, 43 | #[serde(default, skip_serializing_if = "Option::is_none")] 44 | pub domain: Option, 45 | pub extra_domains: Vec, 46 | pub domain_autojoin: bool, 47 | pub domain_restrict: bool, 48 | } 49 | 50 | impl FetchOrgResponse { 51 | pub fn new( 52 | org_id: String, 53 | name: String, 54 | metadata: OrgMetadata, 55 | is_saml_configured: bool, 56 | url_safe_org_slug: String, 57 | can_setup_saml: bool, 58 | is_saml_in_test_mode: bool, 59 | domain_autojoin: bool, 60 | domain_restrict: bool, 61 | ) -> FetchOrgResponse { 62 | FetchOrgResponse { 63 | org_id, 64 | name, 65 | metadata, 66 | is_saml_configured, 67 | max_users: None, 68 | custom_role_mapping_name: None, 69 | legacy_org_id: None, 70 | url_safe_org_slug, 71 | can_setup_saml, 72 | is_saml_in_test_mode, 73 | domain: None, 74 | extra_domains: Vec::new(), 75 | domain_autojoin, 76 | domain_restrict, 77 | } 78 | } 79 | } 80 | 81 | // A Simple org response is used for fetching multiple orgs until that API returns a full org object 82 | #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] 83 | pub struct FetchOrgBasicResponse { 84 | pub org_id: String, 85 | pub name: String, 86 | pub is_saml_configured: bool, 87 | #[serde(default, skip_serializing_if = "OrgMetadata::is_empty")] 88 | pub metadata: OrgMetadata, 89 | #[serde(default, skip_serializing_if = "Option::is_none")] 90 | pub max_users: Option, 91 | #[serde(default, skip_serializing_if = "Option::is_none")] 92 | pub custom_role_mapping_name: Option, 93 | #[serde(default, skip_serializing_if = "Option::is_none")] 94 | pub legacy_org_id: Option, 95 | } 96 | 97 | impl crate::models::FetchOrgBasicResponse { 98 | pub fn new( 99 | org_id: String, 100 | name: String, 101 | metadata: OrgMetadata, 102 | is_saml_configured: bool, 103 | ) -> crate::models::FetchOrgBasicResponse { 104 | crate::models::FetchOrgBasicResponse { 105 | org_id, 106 | name, 107 | metadata, 108 | is_saml_configured, 109 | max_users: None, 110 | custom_role_mapping_name: None, 111 | legacy_org_id: None, 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/apis/access_token_service_api.rs: -------------------------------------------------------------------------------- 1 | use reqwest; 2 | 3 | use super::{configuration, Error}; 4 | use crate::{apis::ResponseContent, propelauth::auth::AUTH_HOSTNAME_HEADER}; 5 | 6 | /// struct for passing parameters to the method [`create_access_token`] 7 | #[derive(Clone, Debug, Default)] 8 | pub struct CreateAccessTokenParams { 9 | pub create_access_token_request: crate::models::CreateAccessTokenRequest, 10 | } 11 | 12 | #[derive(Clone, Debug, Default)] 13 | pub struct CreateAccessTokenV2Params { 14 | pub create_access_token_request: crate::models::CreateAccessTokenV2Request, 15 | } 16 | 17 | /// struct for typed errors of method [`create_access_token`] 18 | #[derive(Debug, Clone, Serialize, Deserialize)] 19 | #[serde(untagged)] 20 | pub enum CreateAccessTokenError { 21 | Status400(crate::models::BadCreateAccessTokenError), 22 | Status401(serde_json::Value), 23 | Status404(serde_json::Value), 24 | UnknownValue(serde_json::Value), 25 | } 26 | 27 | pub async fn create_access_token( 28 | configuration: &configuration::Configuration, 29 | params: CreateAccessTokenParams, 30 | ) -> Result> { 31 | let local_var_configuration = configuration; 32 | 33 | // unbox the parameters 34 | let create_access_token_request = params.create_access_token_request; 35 | 36 | let local_var_client = &local_var_configuration.client; 37 | 38 | let local_var_uri_str = format!( 39 | "{}/api/backend/v1/access_token", 40 | local_var_configuration.base_path 41 | ); 42 | let mut local_var_req_builder = 43 | local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 44 | 45 | if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 46 | local_var_req_builder = 47 | local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 48 | } 49 | if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 50 | local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 51 | }; 52 | local_var_req_builder = local_var_req_builder.header( 53 | AUTH_HOSTNAME_HEADER, 54 | local_var_configuration.auth_hostname.to_owned(), 55 | ); 56 | 57 | local_var_req_builder = local_var_req_builder.json(&create_access_token_request); 58 | 59 | let local_var_req = local_var_req_builder.build()?; 60 | let local_var_resp = local_var_client.execute(local_var_req).await?; 61 | 62 | let local_var_status = local_var_resp.status(); 63 | let local_var_content = local_var_resp.text().await?; 64 | 65 | if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 66 | serde_json::from_str(&local_var_content).map_err(Error::from) 67 | } else { 68 | let local_var_entity: Option = 69 | serde_json::from_str(&local_var_content).ok(); 70 | let local_var_error: ResponseContent = ResponseContent { 71 | status: local_var_status, 72 | content: local_var_content, 73 | entity: local_var_entity, 74 | }; 75 | Err(Error::ResponseError(local_var_error)) 76 | } 77 | } 78 | 79 | pub async fn create_access_token_v2( 80 | configuration: &configuration::Configuration, 81 | params: CreateAccessTokenV2Params, 82 | ) -> Result> { 83 | let local_var_configuration = configuration; 84 | 85 | // unbox the parameters 86 | let create_access_token_request = params.create_access_token_request; 87 | 88 | let local_var_client = &local_var_configuration.client; 89 | 90 | let local_var_uri_str = format!( 91 | "{}/api/backend/v1/access_token", 92 | local_var_configuration.base_path 93 | ); 94 | let mut local_var_req_builder = 95 | local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); 96 | 97 | if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { 98 | local_var_req_builder = 99 | local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); 100 | } 101 | if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { 102 | local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); 103 | }; 104 | local_var_req_builder = local_var_req_builder.header( 105 | AUTH_HOSTNAME_HEADER, 106 | local_var_configuration.auth_hostname.to_owned(), 107 | ); 108 | 109 | local_var_req_builder = local_var_req_builder.json(&create_access_token_request); 110 | 111 | let local_var_req = local_var_req_builder.build()?; 112 | let local_var_resp = local_var_client.execute(local_var_req).await?; 113 | 114 | let local_var_status = local_var_resp.status(); 115 | let local_var_content = local_var_resp.text().await?; 116 | 117 | if !local_var_status.is_client_error() && !local_var_status.is_server_error() { 118 | serde_json::from_str(&local_var_content).map_err(Error::from) 119 | } else { 120 | let local_var_entity: Option = 121 | serde_json::from_str(&local_var_content).ok(); 122 | let local_var_error: ResponseContent = ResponseContent { 123 | status: local_var_status, 124 | content: local_var_content, 125 | entity: local_var_entity, 126 | }; 127 | Err(Error::ResponseError(local_var_error)) 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/rust,intellij+all,vim,emacs,macos,windows,linux 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=rust,intellij+all,vim,emacs,macos,windows,linux 3 | 4 | ### Emacs ### 5 | # -*- mode: gitignore; -*- 6 | *~ 7 | \#*\# 8 | /.emacs.desktop 9 | /.emacs.desktop.lock 10 | *.elc 11 | auto-save-list 12 | tramp 13 | .\#* 14 | 15 | # Org-mode 16 | .org-id-locations 17 | *_archive 18 | 19 | # flymake-mode 20 | *_flymake.* 21 | 22 | # eshell files 23 | /eshell/history 24 | /eshell/lastdir 25 | 26 | # elpa packages 27 | /elpa/ 28 | 29 | # reftex files 30 | *.rel 31 | 32 | # AUCTeX auto folder 33 | /auto/ 34 | 35 | # cask packages 36 | .cask/ 37 | dist/ 38 | 39 | # Flycheck 40 | flycheck_*.el 41 | 42 | # server auth directory 43 | /server/ 44 | 45 | # projectiles files 46 | .projectile 47 | 48 | # directory configuration 49 | .dir-locals.el 50 | 51 | # network security 52 | /network-security.data 53 | 54 | 55 | ### Intellij+all ### 56 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 57 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 58 | 59 | # User-specific stuff 60 | .idea/**/workspace.xml 61 | .idea/**/tasks.xml 62 | .idea/**/usage.statistics.xml 63 | .idea/**/dictionaries 64 | .idea/**/shelf 65 | 66 | # AWS User-specific 67 | .idea/**/aws.xml 68 | 69 | # Generated files 70 | .idea/**/contentModel.xml 71 | 72 | # Sensitive or high-churn files 73 | .idea/**/dataSources/ 74 | .idea/**/dataSources.ids 75 | .idea/**/dataSources.local.xml 76 | .idea/**/sqlDataSources.xml 77 | .idea/**/dynamic.xml 78 | .idea/**/uiDesigner.xml 79 | .idea/**/dbnavigator.xml 80 | 81 | # Gradle 82 | .idea/**/gradle.xml 83 | .idea/**/libraries 84 | 85 | # Gradle and Maven with auto-import 86 | # When using Gradle or Maven with auto-import, you should exclude module files, 87 | # since they will be recreated, and may cause churn. Uncomment if using 88 | # auto-import. 89 | # .idea/artifacts 90 | # .idea/compiler.xml 91 | # .idea/jarRepositories.xml 92 | # .idea/modules.xml 93 | # .idea/*.iml 94 | # .idea/modules 95 | # *.iml 96 | # *.ipr 97 | 98 | # CMake 99 | cmake-build-*/ 100 | 101 | # Mongo Explorer plugin 102 | .idea/**/mongoSettings.xml 103 | 104 | # File-based project format 105 | *.iws 106 | 107 | # IntelliJ 108 | out/ 109 | 110 | # mpeltonen/sbt-idea plugin 111 | .idea_modules/ 112 | 113 | # JIRA plugin 114 | atlassian-ide-plugin.xml 115 | 116 | # Cursive Clojure plugin 117 | .idea/replstate.xml 118 | 119 | # SonarLint plugin 120 | .idea/sonarlint/ 121 | 122 | # Crashlytics plugin (for Android Studio and IntelliJ) 123 | com_crashlytics_export_strings.xml 124 | crashlytics.properties 125 | crashlytics-build.properties 126 | fabric.properties 127 | 128 | # Editor-based Rest Client 129 | .idea/httpRequests 130 | 131 | # Android studio 3.1+ serialized cache file 132 | .idea/caches/build_file_checksums.ser 133 | 134 | ### Intellij+all Patch ### 135 | # Ignore everything but code style settings and run configurations 136 | # that are supposed to be shared within teams. 137 | 138 | .idea/* 139 | 140 | !.idea/codeStyles 141 | !.idea/runConfigurations 142 | 143 | ### Linux ### 144 | 145 | # temporary files which can be created if a process still has a handle open of a deleted file 146 | .fuse_hidden* 147 | 148 | # KDE directory preferences 149 | .directory 150 | 151 | # Linux trash folder which might appear on any partition or disk 152 | .Trash-* 153 | 154 | # .nfs files are created when an open file is removed but is still being accessed 155 | .nfs* 156 | 157 | ### macOS ### 158 | # General 159 | .DS_Store 160 | .AppleDouble 161 | .LSOverride 162 | 163 | # Icon must end with two \r 164 | Icon 165 | 166 | 167 | # Thumbnails 168 | ._* 169 | 170 | # Files that might appear in the root of a volume 171 | .DocumentRevisions-V100 172 | .fseventsd 173 | .Spotlight-V100 174 | .TemporaryItems 175 | .Trashes 176 | .VolumeIcon.icns 177 | .com.apple.timemachine.donotpresent 178 | 179 | # Directories potentially created on remote AFP share 180 | .AppleDB 181 | .AppleDesktop 182 | Network Trash Folder 183 | Temporary Items 184 | .apdisk 185 | 186 | ### macOS Patch ### 187 | # iCloud generated files 188 | *.icloud 189 | 190 | ### Rust ### 191 | # Generated by Cargo 192 | # will have compiled files and executables 193 | debug/ 194 | target/ 195 | 196 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 197 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 198 | Cargo.lock 199 | 200 | # These are backup files generated by rustfmt 201 | **/*.rs.bk 202 | 203 | # MSVC Windows builds of rustc generate these, which store debugging information 204 | *.pdb 205 | 206 | ### Vim ### 207 | # Swap 208 | [._]*.s[a-v][a-z] 209 | !*.svg # comment out if you don't need vector files 210 | [._]*.sw[a-p] 211 | [._]s[a-rt-v][a-z] 212 | [._]ss[a-gi-z] 213 | [._]sw[a-p] 214 | 215 | # Session 216 | Session.vim 217 | Sessionx.vim 218 | 219 | # Temporary 220 | .netrwhist 221 | # Auto-generated tag files 222 | tags 223 | # Persistent undo 224 | [._]*.un~ 225 | 226 | ### Windows ### 227 | # Windows thumbnail cache files 228 | Thumbs.db 229 | Thumbs.db:encryptable 230 | ehthumbs.db 231 | ehthumbs_vista.db 232 | 233 | # Dump file 234 | *.stackdump 235 | 236 | # Folder config file 237 | [Dd]esktop.ini 238 | 239 | # Recycle Bin used on file shares 240 | $RECYCLE.BIN/ 241 | 242 | # Windows Installer files 243 | *.cab 244 | *.msi 245 | *.msix 246 | *.msm 247 | *.msp 248 | 249 | # Windows shortcuts 250 | *.lnk 251 | 252 | # End of https://www.toptal.com/developers/gitignore/api/rust,intellij+all,vim,emacs,macos,windows,linux 253 | -------------------------------------------------------------------------------- /src/propelauth/auth.rs: -------------------------------------------------------------------------------- 1 | use url::Url; 2 | 3 | use crate::apis::auth_service_api::token_verification_metadata; 4 | use crate::apis::configuration::Configuration; 5 | use crate::models::AuthTokenVerificationMetadata; 6 | use crate::propelauth::access_token::AccessTokenService; 7 | use crate::propelauth::api_key::ApiKeyService; 8 | use crate::propelauth::errors::InitializationError; 9 | use crate::propelauth::helpers::map_autogenerated_error; 10 | use crate::propelauth::mfa::MfaService; 11 | use crate::propelauth::options::{AuthOptions, AuthOptionsWithTokenVerification}; 12 | use crate::propelauth::org::OrgService; 13 | use crate::propelauth::token::TokenService; 14 | use crate::propelauth::user::UserService; 15 | use crate::propelauth::employee::EmployeeService; 16 | 17 | static BACKEND_API_BASE_URL: &str = "https://propelauth-api.com"; 18 | pub(crate) static AUTH_HOSTNAME_HEADER: &str = "X-Propelauth-url"; 19 | 20 | /// The main entrypoint of this library. 21 | /// All authentication, authorization and API requests starts from this struct 22 | #[derive(Debug, Clone)] 23 | pub struct PropelAuth { 24 | config: Configuration, 25 | token_verification_metadata: AuthTokenVerificationMetadata, 26 | issuer: String, 27 | } 28 | 29 | impl PropelAuth { 30 | /// Initializes the PropelAuth library without making any external requests. This contrasts 31 | /// with `fetch_and_init` which will fetch the metadata needed to validate access tokens 32 | pub fn init(opts: AuthOptionsWithTokenVerification) -> Result { 33 | let auth_hostname = validate_auth_url_extract_hostname(&opts.auth_url)?; 34 | let issuer = "https://".to_string() + &auth_hostname; 35 | 36 | let configuration = Configuration { 37 | base_path: BACKEND_API_BASE_URL.to_string(), 38 | auth_hostname, 39 | bearer_access_token: Some(opts.api_key), 40 | ..Default::default() 41 | }; 42 | 43 | Ok(PropelAuth { 44 | config: configuration, 45 | token_verification_metadata: opts.manual_token_verification_metadata, 46 | issuer, 47 | }) 48 | } 49 | 50 | /// Initializes the PropelAuth library by making a single external request. This contrasts 51 | /// with `init` where you manually specify the metadata needed to validate access tokens 52 | pub async fn fetch_and_init(opts: AuthOptions) -> Result { 53 | let auth_hostname = validate_auth_url_extract_hostname(&opts.auth_url)?; 54 | let issuer = "https://".to_string() + &auth_hostname; 55 | 56 | let configuration = Configuration { 57 | base_path: BACKEND_API_BASE_URL.to_string(), 58 | auth_hostname, 59 | bearer_access_token: Some(opts.api_key), 60 | ..Default::default() 61 | }; 62 | 63 | let token_verification_metadata = token_verification_metadata(&configuration) 64 | .await 65 | .map_err(|err| { 66 | map_autogenerated_error( 67 | err, 68 | InitializationError::UnexpectedException, 69 | |status, _| match status.as_u16() { 70 | 401 => InitializationError::InvalidApiKey, 71 | 429 => InitializationError::PropelAuthRateLimit, 72 | _ => InitializationError::UnexpectedException, 73 | }, 74 | ) 75 | })?; 76 | 77 | Ok(PropelAuth { 78 | config: configuration, 79 | token_verification_metadata, 80 | issuer, 81 | }) 82 | } 83 | 84 | /// API requests related to users 85 | pub fn user(&self) -> UserService { 86 | UserService { 87 | config: &self.config, 88 | } 89 | } 90 | 91 | /// API requests related to organizations 92 | pub fn org(&self) -> OrgService { 93 | OrgService { 94 | config: &self.config, 95 | } 96 | } 97 | 98 | /// API requests related to organizations 99 | pub fn api_key(&self) -> ApiKeyService { 100 | ApiKeyService { 101 | config: &self.config, 102 | } 103 | } 104 | 105 | /// Verify access tokens from your frontend 106 | pub fn verify(&self) -> TokenService { 107 | TokenService { 108 | token_verification_metadata: &self.token_verification_metadata, 109 | issuer: &self.issuer, 110 | } 111 | } 112 | 113 | /// API requests related to access tokens. 114 | pub fn access_token(&self) -> AccessTokenService { 115 | AccessTokenService { 116 | config: &self.config, 117 | } 118 | } 119 | 120 | /// API requests related to employees. 121 | pub fn employee(&self) -> EmployeeService { 122 | EmployeeService { 123 | config: &self.config, 124 | } 125 | } 126 | 127 | /// API requests related to employees. 128 | pub fn mfa(&self) -> MfaService { 129 | MfaService { 130 | config: &self.config, 131 | } 132 | } 133 | } 134 | 135 | fn validate_auth_url_extract_hostname(auth_url: &str) -> Result { 136 | Ok(Url::parse(auth_url) 137 | .map_err(|_| InitializationError::InvalidAuthUrl)? 138 | .host_str() 139 | .ok_or(InitializationError::InvalidAuthUrl)? 140 | .to_string()) 141 | } 142 | 143 | #[cfg(test)] 144 | mod tests { 145 | use crate::propelauth::auth::validate_auth_url_extract_hostname; 146 | use crate::propelauth::errors::InitializationError; 147 | 148 | #[test] 149 | fn bad_auth_url_is_rejected() { 150 | assert_eq!( 151 | Some(InitializationError::InvalidAuthUrl), 152 | validate_auth_url_extract_hostname("not.a.url").err() 153 | ); 154 | assert_eq!( 155 | Some(InitializationError::InvalidAuthUrl), 156 | validate_auth_url_extract_hostname("fake").err() 157 | ); 158 | } 159 | 160 | #[test] 161 | fn test_extract_hostname() { 162 | assert_eq!( 163 | Some("blah.com".to_string()), 164 | validate_auth_url_extract_hostname("https://blah.com").ok() 165 | ); 166 | 167 | assert!(validate_auth_url_extract_hostname("blah").is_err()); 168 | 169 | assert_eq!( 170 | Some("app.blah.co.uk".to_string()), 171 | validate_auth_url_extract_hostname("https://app.blah.co.uk/more").ok() 172 | ); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 |

6 | 7 | # PropelAuth Rust Library 8 | 9 | Add authentication and authorization to your application. 10 | 11 | This library is meant to be used with a [PropelAuth](https://www.propelauth.com/) account. 12 | You can sign up and get started for free. 13 | 14 | ## Initialize 15 | 16 | First, you'll need to initialize the library. You can either call `PropelAuth::init` 17 | or `PropelAuth::fetch_and_init` (which will fetch any unspecified metadata). 18 | 19 | ```rust 20 | let auth = PropelAuth::fetch_and_init(AuthOptions { 21 | auth_url: "REPLACE_ME".to_string(), 22 | api_key: "REPLACE_ME".to_string(), 23 | }).await.expect("Unable to initialize authentication"); 24 | ``` 25 | 26 | ## Usage / Protecting APIs 27 | 28 | - [Axum](#axum) 29 | - [Actix](#actix) 30 | - [Other](#other) 31 | 32 | Want us to add support for another framework? Reach out at support@propelauth.com 33 | 34 | ## Axum 35 | 36 | To use Axum, make sure to enable the `axum` feature in your Cargo.toml. 37 | 38 | Then, add PropelAuthLayer to your Router: 39 | 40 | ```rust 41 | let auth_layer = PropelAuthLayer::new(auth); 42 | 43 | let app = Router::new() 44 | .route("/whoami", get(whoami)) 45 | .route("/org/:org_name/whoami", get(org_whoami)) 46 | .layer(auth_layer); // <-- here 47 | ``` 48 | 49 | You can then take `User` in as an argument, which will look for an [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) in the Authorization header. 50 | 51 | ```rust 52 | // User will automatically return a 401 (Unauthorized) if a valid access token wasn't provided 53 | async fn whoami(user: User) -> String { 54 | user.user_id 55 | } 56 | ``` 57 | 58 | You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/authorization/rbac) they have. 59 | 60 | ```rust 61 | // If the user isn't in the provided organization, a 403 is returned 62 | async fn org_whoami(user: User, 63 | Path(org_name): Path) -> Result { 64 | let org = user.validate_org_membership(RequiredOrg::OrgName(&org_name), 65 | UserRequirementsInOrg::IsRole("Admin"))?; 66 | Ok(format!("You are a {} in {}", org.user_role, org.org_name)) 67 | } 68 | ``` 69 | 70 | You can also get the full `auth` struct and make API calls with it: 71 | 72 | ```rust 73 | // Extension(auth) is useful for making API requests 74 | async fn make_req(Extension(auth): Extension>) -> String { 75 | let magic_link = auth.user().create_magic_link(CreateMagicLinkRequest { 76 | email: "user@customer.com".to_string(), 77 | ..Default::default() 78 | }).await.expect("Couldn't create magic link"); 79 | magic_link.url 80 | } 81 | ``` 82 | ## Actix 83 | 84 | To use Actix, make sure to enable the `actix4` feature in your Cargo.toml. 85 | 86 | Add your PropelAuth to your Router: 87 | 88 | ```rust 89 | let auth = PropelAuth::fetch_and_init(/*...*/) 90 | //... 91 | HttpServer::new(move || { 92 | App::new() 93 | .service(whoami) 94 | .service(org_whoami) 95 | .app_data(web::Data::new(auth.clone())) // <-- here 96 | }) 97 | ``` 98 | 99 | You can then take `User` in as an argument, which will look for an [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) in the Authorization header. 100 | 101 | ```rust 102 | // User will automatically return a 401 (Unauthorized) if a valid access token wasn't provided 103 | #[get("/whoami")] 104 | async fn whoami(user: User) -> impl Responder { 105 | HttpResponse::Ok().json(user) 106 | } 107 | ``` 108 | 109 | You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/authorization/rbac) they have. 110 | 111 | ```rust 112 | // If the user isn't in the provided organization, a 403 is returned 113 | #[get("/org/{org_name}/whoami")] 114 | async fn whoami(user: User, org_name: web::Path) -> Result { 115 | let org = user.validate_org_membership(RequiredOrg::OrgName(&org_name.into_inner()), 116 | UserRequirementsInOrg::IsRole("Admin"))?; 117 | Ok(HttpResponse::Ok() 118 | .body(format!("You are a {} in {}", org.user_role, org.org_name))) 119 | } 120 | ``` 121 | 122 | You can also get the full `auth` struct and make API calls with it: 123 | 124 | ```rust 125 | #[post("/magic_link")] 126 | async fn make_req(auth: web::Data) -> impl Responder { 127 | let magic_link = auth.user().create_magic_link(CreateMagicLinkRequest { 128 | email: "user@customer.com".to_string(), 129 | ..Default::default() 130 | }).await.expect("Couldn't create magic link"); 131 | HttpResponse::Ok().json(magic_link) 132 | } 133 | ``` 134 | 135 | ## Rustls instead of OpenSSL 136 | 137 | If you'd rather use a pure Rust TLS implementation rather than OpenSSL disable the default features and enable rustls as so: 138 | 139 | ```toml 140 | propelauth = { version >= "0.12.1", features = ["rustls"], default-features = false } 141 | ``` 142 | 143 | ## Other 144 | 145 | After initializing `auth`, you can verify [access tokens](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) by passing in the Authorization header (formatted `Bearer TOKEN`): 146 | 147 | ```rust 148 | let result = auth.verify().validate_authorization_header(&authorization_header); 149 | match result { 150 | Ok(user) => { /* valid access token in the header */ } 151 | Err(_) => { /* invalid access token, typically we return a 401 Unauthorized here */ } 152 | } 153 | ``` 154 | You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/authorization/rbac) they have. 155 | 156 | ```rust 157 | let org = auth.validate_org_membership( 158 | &authorization_header, 159 | RequiredOrg::OrgName("acme"), 160 | UserRequirementsInOrg::IsRole("Admin") 161 | )?; 162 | 163 | // Alternatively, if you already have a user from validate_authorization_header 164 | let org = user.validate_org_membership( 165 | RequiredOrg::OrgName("acme"), 166 | UserRequirementsInOrg::IsRole("Admin") 167 | )?; 168 | ``` 169 | 170 | And finally, you can make API calls directly from `auth.user()` and `auth.org()` 171 | 172 | ## Where do the access tokens come from? 173 | 174 | They come from your frontend. 175 | You can read more about integrating your frontend [here](https://docs.propelauth.com/getting-started/quickstart-fe). 176 | -------------------------------------------------------------------------------- /src/models/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod add_user_to_org_request; 2 | pub use self::add_user_to_org_request::AddUserToOrgRequest; 3 | pub mod create_saml_connection_link_response; 4 | pub use self::create_saml_connection_link_response::CreateSamlConnectionLinkResponse; 5 | pub mod auth_token_verification_metadata; 6 | pub use self::auth_token_verification_metadata::AuthTokenVerificationMetadata; 7 | pub mod bad_create_magic_link_request; 8 | pub use self::bad_create_magic_link_request::BadCreateMagicLinkRequest; 9 | pub mod bad_create_org_request; 10 | pub use self::bad_create_org_request::BadCreateOrgRequest; 11 | pub mod bad_create_user_request; 12 | pub use self::bad_create_user_request::BadCreateUserRequest; 13 | pub mod bad_fetch_org_query; 14 | pub use self::bad_fetch_org_query::BadFetchOrgQuery; 15 | pub mod bad_fetch_users_by_emails_query; 16 | pub use self::bad_fetch_users_by_emails_query::BadFetchUsersByEmailsQuery; 17 | pub mod bad_fetch_users_by_ids_query; 18 | pub use self::bad_fetch_users_by_ids_query::BadFetchUsersByIdsQuery; 19 | pub mod bad_fetch_users_by_query; 20 | pub use self::bad_fetch_users_by_query::BadFetchUsersByQuery; 21 | pub mod bad_fetch_users_by_usernames_query; 22 | pub use self::bad_fetch_users_by_usernames_query::BadFetchUsersByUsernamesQuery; 23 | pub mod bad_fetch_users_in_org_query; 24 | pub use self::bad_fetch_users_in_org_query::BadFetchUsersInOrgQuery; 25 | pub mod bad_migrate_user_request; 26 | pub use self::bad_migrate_user_request::BadMigrateUserRequest; 27 | pub mod bad_migrate_user_password_request; 28 | pub use self::bad_migrate_user_password_request::BadMigrateUserPasswordRequest; 29 | pub mod bad_update_org_request; 30 | pub use self::bad_update_org_request::BadUpdateOrgRequest; 31 | pub mod bad_update_password_request; 32 | pub use self::bad_update_password_request::BadUpdatePasswordRequest; 33 | pub mod bad_update_user_email_request; 34 | pub use self::bad_update_user_email_request::BadUpdateUserEmailRequest; 35 | pub mod bad_update_user_metadata_request; 36 | pub use self::bad_update_user_metadata_request::BadUpdateUserMetadataRequest; 37 | pub mod change_user_role_in_org_request; 38 | pub use self::change_user_role_in_org_request::ChangeUserRoleInOrgRequest; 39 | pub mod create_api_key_response; 40 | pub use self::create_api_key_response::CreateApiKeyResponse; 41 | pub mod create_magic_link_request; 42 | pub use self::create_magic_link_request::CreateMagicLinkRequest; 43 | pub mod create_org_request; 44 | pub use self::create_org_request::CreateOrgRequest; 45 | pub mod create_org_response; 46 | pub use self::create_org_response::CreateOrgResponse; 47 | pub mod create_user_request; 48 | pub use self::create_user_request::CreateUserRequest; 49 | pub mod created_user_response; 50 | pub use self::created_user_response::CreatedUserResponse; 51 | pub mod emails_query; 52 | pub use self::emails_query::EmailsQuery; 53 | pub mod fetch_api_key_response; 54 | pub use self::fetch_api_key_response::FetchApiKeyResponse; 55 | pub mod fetch_api_keys_response; 56 | pub use self::fetch_api_keys_response::FetchApiKeysPagedResponse; 57 | pub mod fetch_custom_role_mappings_response; 58 | pub use self::fetch_custom_role_mappings_response::FetchCustomRoleMappingsResponse; 59 | pub mod fetch_org_order_by; 60 | pub use self::fetch_org_order_by::FetchOrgOrderBy; 61 | pub mod fetch_org_response; 62 | pub use self::fetch_org_response::FetchOrgBasicResponse; 63 | pub use self::fetch_org_response::FetchOrgResponse; 64 | pub mod fetch_orgs_response; 65 | pub use self::fetch_orgs_response::FetchOrgsResponse; 66 | pub mod fetch_users_order_by; 67 | pub use self::fetch_users_order_by::FetchUsersOrderBy; 68 | pub mod magic_link; 69 | pub use self::magic_link::MagicLink; 70 | pub mod migrate_user_request; 71 | pub use self::migrate_user_request::MigrateUserRequest; 72 | pub mod migrate_user_password_request; 73 | pub use self::migrate_user_password_request::MigrateUserPasswordRequest; 74 | pub mod remove_user_from_org_request; 75 | pub use self::remove_user_from_org_request::RemoveUserFromOrgRequest; 76 | pub mod subscribe_org_to_role_mapping_request; 77 | pub use self::subscribe_org_to_role_mapping_request::SubscribeOrgToRoleMappingRequest; 78 | pub mod successful_response; 79 | pub use self::successful_response::SuccessfulResponse; 80 | pub mod update_email_request; 81 | pub use self::update_email_request::UpdateEmailRequest; 82 | pub mod update_metadata_request; 83 | pub use self::update_metadata_request::UpdateMetadataRequest; 84 | pub mod update_org_request; 85 | pub use self::update_org_request::UpdateOrgRequest; 86 | pub mod update_password_request; 87 | pub use self::update_password_request::UpdatePasswordRequest; 88 | pub mod user_ids_query; 89 | pub use self::user_ids_query::UserIdsQuery; 90 | pub mod user_in_org; 91 | pub use self::user_in_org::UserInOrg; 92 | pub mod user_metadata; 93 | pub use self::user_metadata::UserMetadata; 94 | pub mod user_paged_response; 95 | pub use self::user_paged_response::UserPagedResponse; 96 | pub mod usernames_query; 97 | pub use self::usernames_query::UsernamesQuery; 98 | pub mod validate_api_key_response; 99 | pub use self::validate_api_key_response::ValidateApiKeyResponse; 100 | pub mod create_access_token_response; 101 | pub use self::create_access_token_response::CreateAccessTokenResponse; 102 | pub mod create_access_token_request; 103 | pub use self::create_access_token_request::CreateAccessTokenRequest; 104 | pub mod create_access_token_v2_request; 105 | pub use self::create_access_token_v2_request::CreateAccessTokenV2Request; 106 | pub mod bad_create_access_token_error; 107 | pub use self::bad_create_access_token_error::BadCreateAccessTokenError; 108 | pub mod invite_user_to_org_request; 109 | pub use self::invite_user_to_org_request::InviteUserToOrgRequest; 110 | pub mod resend_email_confirmation_request; 111 | pub use self::resend_email_confirmation_request::ResendEmailConfirmationRequest; 112 | pub mod fetch_pending_invites; 113 | pub use self::fetch_pending_invites::FetchPendingInvitesResponse; 114 | pub mod revoke_pending_org_invite_request; 115 | pub use self::revoke_pending_org_invite_request::RevokePendingOrgInviteRequest; 116 | pub mod fetch_saml_sp_metadata_response; 117 | pub use self::fetch_saml_sp_metadata_response::FetchSamlSpMetadataResponse; 118 | pub mod set_saml_idp_metadata_request; 119 | pub use self::set_saml_idp_metadata_request::SetSamlIdpMetadataRequest; 120 | pub mod fetch_api_key_usage_response; 121 | pub use self::fetch_api_key_usage_response::FetchApiKeyUsageResponse; 122 | pub mod import_api_key_response; 123 | pub use self::import_api_key_response::ImportApiKeyResponse; 124 | pub mod fetch_user_signup_query_params_response; 125 | pub use self::fetch_user_signup_query_params_response::FetchSignupQueryParamsResponse; 126 | pub mod fetch_user_mfa_methods_response; 127 | pub use self::fetch_user_mfa_methods_response::FetchUserMfaMethodsResponse; 128 | pub mod verify_totp_challenge_response; 129 | pub use self::verify_totp_challenge_response::VerifyTotpChallengeResponse; 130 | pub mod verify_grant_response; 131 | pub use self::verify_grant_response::VerifyStepUpGrantResponse; 132 | pub mod send_sms_mfa_code_response; 133 | pub use self::send_sms_mfa_code_response::SendSmsCodeResponse; 134 | pub mod verify_sms_challenge_response; 135 | pub use self::verify_sms_challenge_response::VerifySmsChallengeResponse; 136 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! # PropelAuth 2 | //! 3 | //! Add authentication and authorization to your application. 4 | //! 5 | //! This library is meant to be used with a [PropelAuth](https://www.propelauth.com/) account. 6 | //! You can sign up and get started for free. 7 | //! 8 | //! # Initialize 9 | //! 10 | //! First, you'll need to initialize the library. You can either call `PropelAuth::init` 11 | //! or `PropelAuth::fetch_and_init` (which will fetch any unspecified metadata). 12 | //! 13 | //! ```rust 14 | //! let auth = PropelAuth::fetch_and_init(AuthOptions { 15 | //! auth_url: "REPLACE_ME".to_string(), 16 | //! api_key: "REPLACE_ME".to_string(), 17 | //! }).await.expect("Unable to initialize authentication"); 18 | //! ``` 19 | //! 20 | //! # Usage / Protecting APIs 21 | //! 22 | //! - [Axum](#axum) 23 | //! - [Actix](#actix) 24 | //! - [Other](#other) 25 | //! 26 | //! Want us to add support for another framework? Reach out at support@propelauth.com 27 | //! 28 | //! ## Axum 29 | //! 30 | //! To use Axum, make sure to enable the `axum_08` (or `axum_07` or `axum_06`) feature in your Cargo.toml. 31 | //! 32 | //! Then, add PropelAuthLayer to your Router: 33 | //! 34 | //! ```rust 35 | //! let auth_layer = PropelAuthLayer::new(auth); 36 | //! 37 | //! let app = Router::new() 38 | //! .route("/whoami", get(whoami)) 39 | //! .route("/org/:org_name/whoami", get(org_whoami)) 40 | //! .layer(auth_layer); // <-- here 41 | //! ``` 42 | //! 43 | //! You can then take `User` in as an argument, which will look for an [access token](https://docs.propelauth.com/overview/access-token/) in the Authorization header. 44 | //! 45 | //! ```rust 46 | //! // User will automatically return a 401 (Unauthorized) if a valid access token wasn't provided 47 | //! async fn whoami(user: User) -> String { 48 | //! user.user_id 49 | //! } 50 | //! ``` 51 | //! 52 | //! You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/rbac/) they have. 53 | //! 54 | //! ```rust 55 | //! // If the user isn't in the provided organization, a 403 is returned 56 | //! async fn org_whoami(user: User, 57 | //! Path(org_name): Path) -> Result { 58 | //! let org = user.validate_org_membership(RequiredOrg::OrgName(&org_name), 59 | //! UserRequirementsInOrg::IsRole("Admin"))?; 60 | //! Ok(format!("You are a {} in {}", org.user_role, org.org_name)) 61 | //! } 62 | //! ``` 63 | //! 64 | //! You can also get the full `auth` struct and make API calls with it: 65 | //! 66 | //! ```rust 67 | //! // Extension(auth) is useful for making API requests 68 | //! async fn make_req(Extension(auth): Extension>) -> String { 69 | //! let magic_link = auth.user().create_magic_link(CreateMagicLinkRequest { 70 | //! email: "user@customer.com".to_string(), 71 | //! ..Default::default() 72 | //! }).await.expect("Couldn't create magic link"); 73 | //! magic_link.url 74 | //! } 75 | //! ``` 76 | //! ## Actix 77 | //! 78 | //! To use Actix, make sure to enable the `actix4` feature in your Cargo.toml. 79 | //! 80 | //! Add your PropelAuth to your Router: 81 | //! 82 | //! ```rust 83 | //! let auth = PropelAuth::fetch_and_init(/*...*/) 84 | //! //... 85 | //! HttpServer::new(move || { 86 | //! App::new() 87 | //! .service(whoami) 88 | //! .service(org_whoami) 89 | //! .app_data(web::Data::new(auth.clone())) // <-- here 90 | //! }) 91 | //! ``` 92 | //! 93 | //! You can then take `User` in as an argument, which will look for an [access token](https://docs.propelauth.com/overview/access-token/) in the Authorization header. 94 | //! 95 | //! ```rust 96 | //! // User will automatically return a 401 (Unauthorized) if a valid access token wasn't provided 97 | //! #[get("/whoami")] 98 | //! async fn whoami(user: User) -> impl Responder { 99 | //! HttpResponse::Ok().json(user) 100 | //! } 101 | //! ``` 102 | //! 103 | //! You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/rbac/) they have. 104 | //! 105 | //! ```rust 106 | //! // If the user isn't in the provided organization, a 403 is returned 107 | //! #[get("/org/{org_name}/whoami")] 108 | //! async fn whoami(user: User, org_name: web::Path) -> Result { 109 | //! let org = user.validate_org_membership(RequiredOrg::OrgName(&org_name.into_inner()), 110 | //! UserRequirementsInOrg::IsRole("Admin"))?; 111 | //! Ok(HttpResponse::Ok() 112 | //! .body(format!("You are a {} in {}", org.user_role, org.org_name))) 113 | //! } 114 | //! ``` 115 | //! 116 | //! You can also get the full `auth` struct and make API calls with it: 117 | //! 118 | //! ```rust 119 | //! #[post("/magic_link")] 120 | //! async fn make_req(auth: web::Data) -> impl Responder { 121 | //! let magic_link = auth.user().create_magic_link(CreateMagicLinkRequest { 122 | //! email: "user@customer.com".to_string(), 123 | //! ..Default::default() 124 | //! }).await.expect("Couldn't create magic link"); 125 | //! HttpResponse::Ok().json(magic_link) 126 | //! } 127 | //! ``` 128 | //! 129 | //! ## Other 130 | //! 131 | //! After initializing `auth`, you can verify [access tokens](https://docs.propelauth.com/overview/access-token/) by passing in the Authorization header (formatted `Bearer TOKEN`): 132 | //! 133 | //! ```rust 134 | //! let result = auth.verify().validate_authorization_header(&authorization_header); 135 | //! match result { 136 | //! Ok(user) => { /* valid access token in the header */ } 137 | //! Err(_) => { /* invalid access token, typically we return a 401 Unauthorized here */ } 138 | //! } 139 | //! ``` 140 | //! You can also check which [organizations](https://docs.propelauth.com/overview/organizations/) the user is in, and which [roles and permissions](https://docs.propelauth.com/overview/rbac/) they have. 141 | //! 142 | //! ```rust 143 | //! let org = auth.validate_org_membership( 144 | //! &authorization_header, 145 | //! RequiredOrg::OrgName("acme"), 146 | //! UserRequirementsInOrg::IsRole("Admin") 147 | //! )?; 148 | //! 149 | //! // Alternatively, if you already have a user from validate_authorization_header 150 | //! let org = user.validate_org_membership( 151 | //! RequiredOrg::OrgName("acme"), 152 | //! UserRequirementsInOrg::IsRole("Admin") 153 | //! )?; 154 | //! ``` 155 | //! 156 | //! And finally, you can make API calls directly from `auth.user()` and `auth.org()` 157 | //! 158 | //! # Where do the access tokens come from? 159 | //! 160 | //! They come from your frontend. 161 | //! You can read more about integrating your frontend [here](https://docs.propelauth.com/getting-started/frontend-integration/). 162 | 163 | #[macro_use] 164 | extern crate serde_derive; 165 | 166 | extern crate reqwest; 167 | extern crate serde; 168 | extern crate serde_json; 169 | extern crate url; 170 | 171 | pub mod apis; 172 | pub mod models; 173 | pub mod propelauth; 174 | 175 | #[cfg(feature = "axum06")] 176 | pub mod axum06; 177 | 178 | #[cfg(feature = "axum07")] 179 | pub mod axum07; 180 | 181 | #[cfg(feature = "axum08")] 182 | pub mod axum08; 183 | 184 | #[cfg(feature = "actix4")] 185 | pub mod actix; 186 | -------------------------------------------------------------------------------- /src/apis/mfa_service_api.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * propelauth 3 | * 4 | * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) 5 | * 6 | * The version of the OpenAPI document: 0.1.0 7 | * 8 | * Generated by: https://openapi-generator.tech 9 | */ 10 | 11 | use reqwest; 12 | 13 | use super::{configuration, Error}; 14 | use crate::propelauth::auth::AUTH_HOSTNAME_HEADER; 15 | use crate::apis::ResponseContent; 16 | 17 | /// struct for passing parameters to the method [`verify_step_up_mfa_totp_challenge`] 18 | #[derive(Clone, Debug, Default, Serialize)] 19 | pub struct VerifyTotpChallengeParams { 20 | pub action_type: String, 21 | pub user_id: String, 22 | pub code: String, 23 | pub grant_type: String, 24 | pub valid_for_seconds: i64, 25 | } 26 | 27 | /// struct for passing parameters to the method [`verify_step_up_grant`] 28 | #[derive(Clone, Debug, Default, Serialize)] 29 | pub struct VerifyStepUpGrantParams { 30 | pub action_type: String, 31 | pub user_id: String, 32 | pub grant: String, 33 | } 34 | 35 | /// struct for passing parameters to the method [`send_sms_mfa_code`] 36 | #[derive(Clone, Debug, Default, Serialize)] 37 | pub struct SendSmsMfaCodeParams { 38 | pub action_type: String, 39 | pub user_id: String, 40 | pub mfa_phone_id: String, 41 | pub grant_type: String, 42 | pub valid_for_seconds: i64, 43 | } 44 | 45 | /// struct for passing parameters to the method [`verify_sms_challenge`] 46 | #[derive(Clone, Debug, Default, Serialize)] 47 | pub struct VerifySmsChallengeParams { 48 | pub challenge_id: String, 49 | pub user_id: String, 50 | pub code: String, 51 | } 52 | 53 | 54 | 55 | #[derive(Debug, Clone, Deserialize)] 56 | #[serde(untagged)] 57 | pub enum StepUpMfaError { 58 | InvalidIntegrationAPIKey, 59 | PropelAuthRateLimit, 60 | NotFound, 61 | UnknownValue(serde_json::Value), 62 | UnknownError, 63 | UnexpectedExceptionWithSDK, 64 | } 65 | 66 | 67 | pub async fn verify_step_up_totp_challenge( 68 | configuration: &configuration::Configuration, 69 | params: VerifyTotpChallengeParams, 70 | ) -> Result> { 71 | let client = &configuration.client; 72 | 73 | let uri = format!( 74 | "{}/api/backend/v1/mfa/step-up/verify-totp", 75 | configuration.base_path 76 | ); 77 | let mut req_builder = client.request(reqwest::Method::POST, uri.as_str()); 78 | 79 | if let Some(ref user_agent) = configuration.user_agent { 80 | req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); 81 | } 82 | if let Some(ref bearer_token) = configuration.bearer_access_token { 83 | req_builder = req_builder.bearer_auth(bearer_token.to_owned()); 84 | } 85 | req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned()); 86 | 87 | req_builder = req_builder.json(¶ms); 88 | 89 | let req = req_builder.build()?; 90 | let resp = client.execute(req).await?; 91 | 92 | let status = resp.status(); 93 | let content = resp.text().await?; 94 | 95 | if !status.is_client_error() && !status.is_server_error() { 96 | serde_json::from_str(&content).map_err(Error::from) 97 | } else { 98 | let entity: Option = serde_json::from_str(&content).ok(); 99 | let error = ResponseContent { 100 | status, 101 | content, 102 | entity, 103 | }; 104 | Err(Error::ResponseError(error)) 105 | } 106 | } 107 | 108 | pub async fn verify_step_up_grant( 109 | configuration: &configuration::Configuration, 110 | params: VerifyStepUpGrantParams, 111 | ) -> Result> { 112 | let client = &configuration.client; 113 | 114 | let uri = format!( 115 | "{}/api/backend/v1/mfa/step-up/verify-grant", 116 | configuration.base_path 117 | ); 118 | let mut req_builder = client.request(reqwest::Method::POST, uri.as_str()); 119 | 120 | if let Some(ref user_agent) = configuration.user_agent { 121 | req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); 122 | } 123 | if let Some(ref bearer_token) = configuration.bearer_access_token { 124 | req_builder = req_builder.bearer_auth(bearer_token.to_owned()); 125 | } 126 | req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned()); 127 | 128 | req_builder = req_builder.json(¶ms); 129 | 130 | let req = req_builder.build()?; 131 | let resp = client.execute(req).await?; 132 | 133 | let status = resp.status(); 134 | let content = resp.text().await?; 135 | 136 | if !status.is_client_error() && !status.is_server_error() { 137 | Ok(crate::models::successful_response::SuccessfulResponse { message: None }) 138 | } else { 139 | let entity: Option = serde_json::from_str(&content).ok(); 140 | let error = ResponseContent { 141 | status, 142 | content, 143 | entity, 144 | }; 145 | Err(Error::ResponseError(error)) 146 | } 147 | } 148 | 149 | pub async fn send_sms_mfa_code( 150 | configuration: &configuration::Configuration, 151 | params: SendSmsMfaCodeParams, 152 | ) -> Result> { 153 | let client = &configuration.client; 154 | 155 | let uri = format!( 156 | "{}/api/backend/v1/mfa/step-up/phone/send", 157 | configuration.base_path 158 | ); 159 | let mut req_builder = client.request(reqwest::Method::POST, uri.as_str()); 160 | 161 | if let Some(ref user_agent) = configuration.user_agent { 162 | req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); 163 | } 164 | if let Some(ref bearer_token) = configuration.bearer_access_token { 165 | req_builder = req_builder.bearer_auth(bearer_token.to_owned()); 166 | } 167 | req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned()); 168 | 169 | req_builder = req_builder.json(¶ms); 170 | 171 | let req = req_builder.build()?; 172 | let resp = client.execute(req).await?; 173 | 174 | let status = resp.status(); 175 | let content = resp.text().await?; 176 | 177 | if !status.is_client_error() && !status.is_server_error() { 178 | serde_json::from_str(&content).map_err(Error::from) 179 | } else { 180 | let entity: Option = serde_json::from_str(&content).ok(); 181 | let error = ResponseContent { 182 | status, 183 | content, 184 | entity, 185 | }; 186 | Err(Error::ResponseError(error)) 187 | } 188 | } 189 | 190 | pub async fn verify_sms_challenge( 191 | configuration: &configuration::Configuration, 192 | params: VerifySmsChallengeParams, 193 | ) -> Result> { 194 | let client = &configuration.client; 195 | 196 | let uri = format!( 197 | "{}/api/backend/v1/mfa/step-up/phone/verify", 198 | configuration.base_path 199 | ); 200 | let mut req_builder = client.request(reqwest::Method::POST, uri.as_str()); 201 | 202 | if let Some(ref user_agent) = configuration.user_agent { 203 | req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); 204 | } 205 | if let Some(ref bearer_token) = configuration.bearer_access_token { 206 | req_builder = req_builder.bearer_auth(bearer_token.to_owned()); 207 | } 208 | req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned()); 209 | 210 | req_builder = req_builder.json(¶ms); 211 | 212 | let req = req_builder.build()?; 213 | let resp = client.execute(req).await?; 214 | 215 | let status = resp.status(); 216 | let content = resp.text().await?; 217 | 218 | if !status.is_client_error() && !status.is_server_error() { 219 | serde_json::from_str(&content).map_err(Error::from) 220 | } else { 221 | let entity: Option = serde_json::from_str(&content).ok(); 222 | let error = ResponseContent { 223 | status, 224 | content, 225 | entity, 226 | }; 227 | Err(Error::ResponseError(error)) 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /src/propelauth/mfa.rs: -------------------------------------------------------------------------------- 1 | use crate::apis::configuration::Configuration; 2 | use crate::apis::mfa_service_api::{StepUpMfaError, VerifySmsChallengeParams, VerifyStepUpGrantParams}; 3 | use crate::apis::Error; 4 | use crate::models::{SendSmsCodeResponse, VerifySmsChallengeResponse, VerifyStepUpGrantResponse}; 5 | use crate::propelauth::errors::{VerifyStepUpGrantError, VerifyStepUpTotpChallengeError, SendSmsCodeError, VerifySmsChallengeError}; 6 | use crate::propelauth::helpers::map_autogenerated_error; 7 | use crate::models::VerifyTotpChallengeResponse; 8 | use crate::apis::mfa_service_api::{SendSmsMfaCodeParams, VerifyTotpChallengeParams}; 9 | 10 | pub struct MfaService<'a> { 11 | pub(crate) config: &'a Configuration, 12 | } 13 | 14 | impl MfaService<'_> { 15 | pub async fn verify_step_up_totp_challenge( 16 | &self, 17 | params: VerifyTotpChallengeParams, 18 | ) -> Result { 19 | let result = 20 | crate::apis::mfa_service_api::verify_step_up_totp_challenge(&self.config, params).await; 21 | 22 | match result { 23 | Ok(response) => Ok(response), 24 | Err(Error::ResponseError(response)) => { 25 | if response.status == 401 { 26 | return Err(VerifyStepUpTotpChallengeError::InvalidApiKey); 27 | } else if response.status == 429 { 28 | return Err(VerifyStepUpTotpChallengeError::PropelAuthRateLimit); 29 | } 30 | 31 | let error_response: Result = 32 | serde_json::from_str(&response.content); 33 | if let Ok(error_json) = error_response { 34 | if let Some(error_code) = error_json.get("error_code").and_then(|v| v.as_str()) 35 | { 36 | match error_code { 37 | "user_not_found" => { 38 | return Err(VerifyStepUpTotpChallengeError::UserNotFound) 39 | } 40 | "mfa_not_enabled" => { 41 | return Err(VerifyStepUpTotpChallengeError::MfaNotEnabled) 42 | } 43 | "incorrect_mfa_code" => { 44 | return Err(VerifyStepUpTotpChallengeError::IncorrectMfaCode) 45 | } 46 | "invalid_request_fields" => { 47 | return Err(VerifyStepUpTotpChallengeError::BadRequest( 48 | response.content, 49 | )) 50 | } 51 | "feature_gated" => { 52 | return Err(VerifyStepUpTotpChallengeError::FeatureGated) 53 | } 54 | _ => {} 55 | } 56 | } 57 | } 58 | 59 | Err(VerifyStepUpTotpChallengeError::UnexpectedException) 60 | } 61 | Err(_) => Err(VerifyStepUpTotpChallengeError::UnexpectedException), 62 | } 63 | } 64 | 65 | pub async fn verify_step_up_grant( 66 | &self, 67 | params: VerifyStepUpGrantParams, 68 | ) -> Result { 69 | let result = 70 | crate::apis::mfa_service_api::verify_step_up_grant(&self.config, params).await; 71 | 72 | match result { 73 | Ok(_) => Ok(VerifyStepUpGrantResponse { success: true }), 74 | Err(Error::ResponseError(response)) => { 75 | if response.status == 401 { 76 | return Err(VerifyStepUpGrantError::InvalidApiKey); 77 | } else if response.status == 429 { 78 | return Err(VerifyStepUpGrantError::PropelAuthRateLimit); 79 | } 80 | 81 | let error_response: Result = 82 | serde_json::from_str(&response.content); 83 | if let Ok(error_json) = error_response { 84 | if let Some(error_code) = error_json.get("error_code").and_then(|v| v.as_str()) 85 | { 86 | match error_code { 87 | "invalid_request_fields" => { 88 | if let Some(field_to_errors) = 89 | error_json.get("field_to_errors").and_then(|v| v.as_object()) 90 | { 91 | if let Some(grant_error) = 92 | field_to_errors.get("grant").and_then(|v| v.as_str()) 93 | { 94 | if grant_error == "grant_not_found" { 95 | return Ok(VerifyStepUpGrantResponse { success: false }); 96 | } 97 | } 98 | } 99 | 100 | return Err(VerifyStepUpGrantError::BadRequest(response.content)); 101 | } 102 | "feature_gated" => { 103 | return Err(VerifyStepUpGrantError::FeatureGated) 104 | } 105 | _ => {} 106 | } 107 | } 108 | } 109 | 110 | Err(VerifyStepUpGrantError::UnexpectedException) 111 | } 112 | Err(_) => Err(VerifyStepUpGrantError::UnexpectedException), 113 | } 114 | } 115 | 116 | pub async fn send_sms_mfa_code( 117 | &self, 118 | params: SendSmsMfaCodeParams, 119 | ) -> Result { 120 | let result = 121 | crate::apis::mfa_service_api::send_sms_mfa_code(&self.config, params).await; 122 | 123 | match result { 124 | Ok(response) => Ok(response), 125 | Err(Error::ResponseError(response)) => { 126 | if response.status == 401 { 127 | return Err(SendSmsCodeError::InvalidApiKey); 128 | } else if response.status == 429 { 129 | return Err(SendSmsCodeError::PropelAuthRateLimit); 130 | } 131 | 132 | let error_response: Result = 133 | serde_json::from_str(&response.content); 134 | if let Ok(error_json) = error_response { 135 | if let Some(error_code) = error_json.get("error_code").and_then(|v| v.as_str()) 136 | { 137 | match error_code { 138 | "user_not_found" => { 139 | return Err(SendSmsCodeError::UserNotFound) 140 | } 141 | "mfa_not_enabled" => { 142 | return Err(SendSmsCodeError::MfaNotEnabled) 143 | } 144 | "invalid_request_fields" => { 145 | return Err(SendSmsCodeError::BadRequest( 146 | response.content, 147 | )) 148 | } 149 | "feature_gated" => { 150 | return Err(SendSmsCodeError::FeatureGated) 151 | } 152 | _ => {} 153 | } 154 | } 155 | } 156 | Err(SendSmsCodeError::UnexpectedException) 157 | } 158 | Err(_) => Err(SendSmsCodeError::UnexpectedException), 159 | } 160 | } 161 | 162 | pub async fn verify_sms_challenge( 163 | &self, 164 | params: VerifySmsChallengeParams, 165 | ) -> Result { 166 | let result = 167 | crate::apis::mfa_service_api::verify_sms_challenge(&self.config, params).await; 168 | 169 | match result { 170 | Ok(response) => Ok(response), 171 | Err(Error::ResponseError(response)) => { 172 | if response.status == 401 { 173 | return Err(VerifySmsChallengeError::InvalidApiKey); 174 | } else if response.status == 429 { 175 | return Err(VerifySmsChallengeError::PropelAuthRateLimit); 176 | } 177 | 178 | let error_response: Result = 179 | serde_json::from_str(&response.content); 180 | if let Ok(error_json) = error_response { 181 | if let Some(error_code) = error_json.get("error_code").and_then(|v| v.as_str()) 182 | { 183 | match error_code { 184 | "user_not_found" => { 185 | return Err(VerifySmsChallengeError::UserNotFound) 186 | } 187 | "mfa_not_enabled" => { 188 | return Err(VerifySmsChallengeError::MfaNotEnabled) 189 | } 190 | "invalid_request_fields" => { 191 | return Err(VerifySmsChallengeError::BadRequest( 192 | response.content, 193 | )) 194 | } 195 | "feature_gated" => { 196 | return Err(VerifySmsChallengeError::FeatureGated) 197 | } 198 | _ => {} 199 | } 200 | } 201 | } 202 | Err(VerifySmsChallengeError::UnexpectedException) 203 | } 204 | Err(_) => Err(VerifySmsChallengeError::UnexpectedException), 205 | } 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/propelauth/token_models.rs: -------------------------------------------------------------------------------- 1 | use std::collections::hash_map::{Keys, Values}; 2 | use std::collections::HashMap; 3 | 4 | use serde::{Deserialize, Serialize}; 5 | use serde_json::Value; 6 | 7 | use crate::propelauth::errors::DetailedForbiddenError; 8 | use crate::propelauth::options::{RequiredOrg, UserRequirementsInOrg}; 9 | 10 | #[derive(Debug, Deserialize, Clone, PartialEq, Default)] 11 | pub struct LoginMethodForAccessToken { 12 | pub login_method: String, 13 | #[serde(default)] 14 | pub provider: Option, 15 | #[serde(default)] 16 | pub org_id: Option, 17 | } 18 | 19 | #[derive(Debug, Serialize, Deserialize, Hash, Eq, PartialEq, Copy, Clone)] 20 | #[serde(rename_all = "snake_case")] 21 | pub enum SocialLoginType { 22 | Google, 23 | Github, 24 | Microsoft, 25 | Slack, 26 | Salesforce, 27 | Linkedin, 28 | Quickbooks, 29 | Xero, 30 | } 31 | 32 | impl std::str::FromStr for SocialLoginType { 33 | type Err = String; 34 | 35 | fn from_str(s: &str) -> Result { 36 | match s { 37 | "Google" => Ok(SocialLoginType::Google), 38 | "GitHub" => Ok(SocialLoginType::Github), 39 | "Microsoft" => Ok(SocialLoginType::Microsoft), 40 | "Slack" => Ok(SocialLoginType::Slack), 41 | "Salesforce" => Ok(SocialLoginType::Salesforce), 42 | "LinkedIn" => Ok(SocialLoginType::Linkedin), 43 | "QuickBooks Online" => Ok(SocialLoginType::Quickbooks), 44 | "Xero" => Ok(SocialLoginType::Xero), 45 | _ => Err("invalid social login type".to_string()), 46 | } 47 | } 48 | } 49 | 50 | #[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq)] 51 | pub enum IdentityProvider { 52 | Google, 53 | Rippling, 54 | OneLogin, 55 | JumpCloud, 56 | Okta, 57 | Azure, 58 | Duo, 59 | Generic, 60 | } 61 | 62 | impl std::str::FromStr for IdentityProvider { 63 | type Err = String; 64 | 65 | fn from_str(s: &str) -> Result { 66 | match s { 67 | "Google" => Ok(IdentityProvider::Google), 68 | "Rippling" => Ok(IdentityProvider::Rippling), 69 | "OneLogin" => Ok(IdentityProvider::OneLogin), 70 | "JumpCloud" => Ok(IdentityProvider::JumpCloud), 71 | "Okta" => Ok(IdentityProvider::Okta), 72 | "Azure" => Ok(IdentityProvider::Azure), 73 | "Duo" => Ok(IdentityProvider::Duo), 74 | "Generic" => Ok(IdentityProvider::Generic), 75 | _ => Err("invalid identity provider".to_string()), 76 | } 77 | } 78 | } 79 | 80 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)] 81 | pub enum LoginMethod { 82 | Password, 83 | MagicLink, 84 | SocialSso(SocialLoginType), 85 | EmailConfirmationLink, 86 | SamlSso(IdentityProvider, String), 87 | Impersonation, 88 | TokenGeneratedFromBackendApi, 89 | #[default] 90 | Unknown, 91 | } 92 | 93 | impl Into for LoginMethodForAccessToken { 94 | fn into(self) -> LoginMethod { 95 | match self.login_method.as_str() { 96 | "password" => LoginMethod::Password, 97 | "magic_link" => LoginMethod::MagicLink, 98 | "social_sso" => LoginMethod::SocialSso( 99 | self.provider 100 | .expect("provider is required for social_sso login method") 101 | .parse::() 102 | .expect("invalid social login type for social_sso login method"), 103 | ), 104 | "email_confirmation_link" => LoginMethod::EmailConfirmationLink, 105 | "saml_sso" => LoginMethod::SamlSso( 106 | self.provider 107 | .expect("provider is required for saml_sso login method") 108 | .parse::() 109 | .expect("invalid identity provider for saml_sso login method"), 110 | self.org_id 111 | .expect("org_id is required for saml_sso login method"), 112 | ), 113 | "impersonation" => LoginMethod::Impersonation, 114 | "generated_from_backend_api" => LoginMethod::TokenGeneratedFromBackendApi, 115 | _ => LoginMethod::Unknown, 116 | } 117 | } 118 | } 119 | 120 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)] 121 | pub struct User { 122 | pub user_id: String, 123 | 124 | #[serde(default)] 125 | pub org_id_to_org_member_info: HashMap, 126 | 127 | #[serde(default)] 128 | pub active_org_id: Option, 129 | 130 | pub email: String, 131 | #[serde(default)] 132 | pub first_name: Option, 133 | #[serde(default)] 134 | pub last_name: Option, 135 | #[serde(default)] 136 | pub username: Option, 137 | #[serde(default)] 138 | pub properties: Option>, 139 | #[serde(default)] 140 | pub metadata: HashMap, 141 | 142 | /** If you used our migration APIs to migrate this user from a different system, 143 | * this is their original ID from that system. */ 144 | #[serde(default)] 145 | pub legacy_user_id: Option, 146 | 147 | #[serde(default)] 148 | pub impersonator_user_id: Option, 149 | 150 | #[serde(default)] 151 | pub login_method: LoginMethod, 152 | } 153 | 154 | impl User { 155 | pub fn validate_org_membership( 156 | &self, 157 | required_org: RequiredOrg, 158 | user_requirements_in_org: UserRequirementsInOrg, 159 | ) -> Result { 160 | let org_member_info = self 161 | .get_org(required_org) 162 | .ok_or(DetailedForbiddenError::UserIsNotInOrg)?; 163 | 164 | match user_requirements_in_org { 165 | UserRequirementsInOrg::None => Ok(org_member_info.clone()), 166 | UserRequirementsInOrg::IsRole(required_role) => { 167 | if org_member_info.is_role(required_role) { 168 | Ok(org_member_info.clone()) 169 | } else { 170 | Err(DetailedForbiddenError::UserRoleDoesntMatch) 171 | } 172 | } 173 | UserRequirementsInOrg::IsAtLeastRole(minimum_required_role) => { 174 | if org_member_info.is_at_least_role(minimum_required_role) { 175 | Ok(org_member_info.clone()) 176 | } else { 177 | Err(DetailedForbiddenError::UserRoleDoesntMatch) 178 | } 179 | } 180 | UserRequirementsInOrg::HasPermission(permission) => { 181 | if org_member_info.has_permission(permission) { 182 | Ok(org_member_info.clone()) 183 | } else { 184 | Err(DetailedForbiddenError::UserMissingPermission) 185 | } 186 | } 187 | UserRequirementsInOrg::HasAllPermissions(permissions) => { 188 | if org_member_info.has_all_permissions(permissions) { 189 | Ok(org_member_info.clone()) 190 | } else { 191 | Err(DetailedForbiddenError::UserMissingPermission) 192 | } 193 | } 194 | } 195 | } 196 | 197 | pub fn get_org(&self, org: RequiredOrg) -> Option<&OrgMemberInfo> { 198 | match org { 199 | RequiredOrg::OrgId(required_org_id) => { 200 | self.org_id_to_org_member_info.get(required_org_id) 201 | } 202 | RequiredOrg::OrgName(required_org_name) => { 203 | self.get_all_orgs().find(|org_member_info| { 204 | org_member_info.org_name == required_org_name 205 | || org_member_info.url_safe_org_name == required_org_name 206 | }) 207 | } 208 | } 209 | } 210 | 211 | pub fn get_active_org(&self) -> Option<&OrgMemberInfo> { 212 | match &self.active_org_id { 213 | Some(org_id) => self.get_org(RequiredOrg::OrgId(org_id)), 214 | None => None, 215 | } 216 | } 217 | 218 | pub fn get_active_org_id(&self) -> Option<&String> { 219 | self.active_org_id.as_ref() 220 | } 221 | 222 | pub fn get_all_orgs(&self) -> Values<'_, String, OrgMemberInfo> { 223 | self.org_id_to_org_member_info.values() 224 | } 225 | 226 | pub fn get_all_org_ids(&self) -> Keys<'_, String, OrgMemberInfo> { 227 | self.org_id_to_org_member_info.keys() 228 | } 229 | 230 | pub fn get_num_orgs(&self) -> usize { 231 | self.org_id_to_org_member_info.len() 232 | } 233 | 234 | pub fn is_impersonated(&self) -> bool { 235 | self.impersonator_user_id.is_some() 236 | } 237 | } 238 | 239 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] 240 | pub struct OrgMemberInfo { 241 | pub org_id: String, 242 | pub org_name: String, 243 | pub org_metadata: HashMap, 244 | pub url_safe_org_name: String, 245 | pub org_role_structure: OrgRoleStructure, 246 | pub user_role: String, 247 | pub inherited_user_roles_plus_current_role: Vec, 248 | pub user_permissions: Vec, 249 | pub additional_roles: Vec, 250 | } 251 | 252 | #[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)] 253 | pub enum OrgRoleStructure { 254 | #[default] 255 | #[serde(rename = "single_role_in_hierarchy")] 256 | SingleRoleInHierarchy, 257 | #[serde(rename = "multi_role")] 258 | MultiRole, 259 | } 260 | 261 | impl OrgMemberInfo { 262 | pub fn is_role(&self, role: &str) -> bool { 263 | match self.org_role_structure { 264 | OrgRoleStructure::SingleRoleInHierarchy => self.user_role == role, 265 | OrgRoleStructure::MultiRole => { 266 | self.user_role == role || self.additional_roles.iter().any(|r| r == role) 267 | } 268 | } 269 | } 270 | 271 | pub fn is_at_least_role(&self, role: &str) -> bool { 272 | match self.org_role_structure { 273 | OrgRoleStructure::SingleRoleInHierarchy => self 274 | .inherited_user_roles_plus_current_role 275 | .iter() 276 | .any(|r| r == role), 277 | OrgRoleStructure::MultiRole => { 278 | self.user_role == role || self.additional_roles.iter().any(|r| r == role) 279 | } 280 | } 281 | } 282 | 283 | pub fn has_permission(&self, permission: &str) -> bool { 284 | for user_permission in &self.user_permissions { 285 | if user_permission == permission { 286 | return true; 287 | } 288 | } 289 | false 290 | } 291 | 292 | pub fn has_all_permissions(&self, permissions: Vec<&str>) -> bool { 293 | // This is n^2, but for small number of permissions should be fine 294 | for permission in permissions { 295 | if !self.has_permission(permission) { 296 | return false; 297 | } 298 | } 299 | true 300 | } 301 | } 302 | 303 | #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] 304 | pub struct UserAndOrgMemberInfo { 305 | pub user: User, 306 | pub org_member_info: OrgMemberInfo, 307 | } 308 | -------------------------------------------------------------------------------- /docs/OrgServiceApi.md: -------------------------------------------------------------------------------- 1 | # \OrgServiceApi 2 | 3 | All URIs are relative to _http://localhost_ 4 | 5 | | Method | HTTP request | Description | 6 | | ------------------------------------------------------------------------- | --------------------------------------------------- | ----------- | 7 | | [**add_user_to_org**](OrgServiceApi.md#add_user_to_org) | **POST** /api/backend/v1/org/add_user | 8 | | [**allow_org_to_enable_saml**](OrgServiceApi.md#allow_org_to_enable_saml) | **POST** /api/backend/v1/org/{org_id}/allow_saml | 9 | | [**change_user_role_in_org**](OrgServiceApi.md#change_user_role_in_org) | **POST** /api/backend/v1/org/change_role | 10 | | [**create_org**](OrgServiceApi.md#create_org) | **POST** /api/backend/v1/org/ | 11 | | [**disallow_saml**](OrgServiceApi.md#disallow_saml) | **POST** /api/backend/v1/org/{org_id}/disallow_saml | 12 | | [**fetch_org**](OrgServiceApi.md#fetch_org) | **GET** /api/backend/v1/org/{org_id} | 13 | | [**fetch_orgs_by_query**](OrgServiceApi.md#fetch_orgs_by_query) | **GET** /api/backend/v1/org/query | 14 | | [**fetch_users_in_org**](OrgServiceApi.md#fetch_users_in_org) | **GET** /api/backend/v1/user/org/{org_id} | 15 | | [**remove_user_from_org**](OrgServiceApi.md#remove_user_from_org) | **POST** /api/backend/v1/org/remove_user | 16 | | [**update_org**](OrgServiceApi.md#update_org) | **PUT** /api/backend/v1/org/{org_id} | 17 | | [**delete_org**](OrgServiceApi.md#delete_org) | **DELETE** /api/backend/v1/org/{org_id} | 18 | 19 | ## add_user_to_org 20 | 21 | > crate::models::SuccessfulResponse add_user_to_org(add_user_to_org_request) 22 | 23 | ### Parameters 24 | 25 | | Name | Type | Description | Required | Notes | 26 | | --------------------------- | ------------------------------------------------- | ----------- | ---------- | ----- | 27 | | **add_user_to_org_request** | [**AddUserToOrgRequest**](AddUserToOrgRequest.md) | | [required] | 28 | 29 | ### Return type 30 | 31 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 32 | 33 | ### Authorization 34 | 35 | [BearerAuth](../README.md#BearerAuth) 36 | 37 | ### HTTP request headers 38 | 39 | - **Content-Type**: application/json 40 | - **Accept**: application/json 41 | 42 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 43 | 44 | ## allow_org_to_enable_saml 45 | 46 | > crate::models::SuccessfulResponse allow_org_to_enable_saml(org_id) 47 | 48 | ### Parameters 49 | 50 | | Name | Type | Description | Required | Notes | 51 | | ---------- | ---------- | ----------- | ---------- | ----- | 52 | | **org_id** | **String** | | [required] | 53 | 54 | ### Return type 55 | 56 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 57 | 58 | ### Authorization 59 | 60 | [BearerAuth](../README.md#BearerAuth) 61 | 62 | ### HTTP request headers 63 | 64 | - **Content-Type**: Not defined 65 | - **Accept**: application/json 66 | 67 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 68 | 69 | ## change_user_role_in_org 70 | 71 | > crate::models::SuccessfulResponse change_user_role_in_org(change_user_role_in_org_request) 72 | 73 | ### Parameters 74 | 75 | | Name | Type | Description | Required | Notes | 76 | | ----------------------------------- | --------------------------------------------------------------- | ----------- | ---------- | ----- | 77 | | **change_user_role_in_org_request** | [**ChangeUserRoleInOrgRequest**](ChangeUserRoleInOrgRequest.md) | | [required] | 78 | 79 | ### Return type 80 | 81 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 82 | 83 | ### Authorization 84 | 85 | [BearerAuth](../README.md#BearerAuth) 86 | 87 | ### HTTP request headers 88 | 89 | - **Content-Type**: application/json 90 | - **Accept**: application/json 91 | 92 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 93 | 94 | ## create_org 95 | 96 | > crate::models::CreateOrgResponse create_org(create_org_request) 97 | 98 | ### Parameters 99 | 100 | | Name | Type | Description | Required | Notes | 101 | | ---------------------- | ------------------------------------------- | ----------- | ---------- | ----- | 102 | | **create_org_request** | [**CreateOrgRequest**](CreateOrgRequest.md) | | [required] | 103 | 104 | ### Return type 105 | 106 | [**crate::models::CreateOrgResponse**](CreateOrgResponse.md) 107 | 108 | ### Authorization 109 | 110 | [BearerAuth](../README.md#BearerAuth) 111 | 112 | ### HTTP request headers 113 | 114 | - **Content-Type**: application/json 115 | - **Accept**: application/json 116 | 117 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 118 | 119 | ## disallow_saml 120 | 121 | > crate::models::SuccessfulResponse disallow_saml(org_id) 122 | 123 | ### Parameters 124 | 125 | | Name | Type | Description | Required | Notes | 126 | | ---------- | ---------- | ----------- | ---------- | ----- | 127 | | **org_id** | **String** | | [required] | 128 | 129 | ### Return type 130 | 131 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 132 | 133 | ### Authorization 134 | 135 | [BearerAuth](../README.md#BearerAuth) 136 | 137 | ### HTTP request headers 138 | 139 | - **Content-Type**: Not defined 140 | - **Accept**: application/json 141 | 142 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 143 | 144 | ## fetch_org 145 | 146 | > crate::models::FetchOrgResponse fetch_org(org_id) 147 | 148 | ### Parameters 149 | 150 | | Name | Type | Description | Required | Notes | 151 | | ---------- | ---------- | ----------- | ---------- | ----- | 152 | | **org_id** | **String** | | [required] | 153 | 154 | ### Return type 155 | 156 | [**crate::models::FetchOrgResponse**](FetchOrgResponse.md) 157 | 158 | ### Authorization 159 | 160 | [BearerAuth](../README.md#BearerAuth) 161 | 162 | ### HTTP request headers 163 | 164 | - **Content-Type**: Not defined 165 | - **Accept**: application/json 166 | 167 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 168 | 169 | ## fetch_orgs_by_query 170 | 171 | > crate::models::FetchOrgsResponse fetch_orgs_by_query(page_size, page_number, order_by) 172 | 173 | ### Parameters 174 | 175 | | Name | Type | Description | Required | Notes | 176 | | --------------- | ---------------------------------- | ----------- | -------- | ----- | 177 | | **page_size** | Option<**i64**> | | | 178 | | **page_number** | Option<**i64**> | | | 179 | | **order_by** | Option<[**FetchOrgOrderBy**](.md)> | | | 180 | 181 | ### Return type 182 | 183 | [**crate::models::FetchOrgsResponse**](FetchOrgsResponse.md) 184 | 185 | ### Authorization 186 | 187 | [BearerAuth](../README.md#BearerAuth) 188 | 189 | ### HTTP request headers 190 | 191 | - **Content-Type**: Not defined 192 | - **Accept**: application/json 193 | 194 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 195 | 196 | ## fetch_users_in_org 197 | 198 | > crate::models::UserPagedResponse fetch_users_in_org(org_id, page_size, page_number, include_orgs) 199 | 200 | ### Parameters 201 | 202 | | Name | Type | Description | Required | Notes | 203 | | ---------------- | ---------------- | ----------------- | ---------- | ----- | 204 | | **org_id** | **String** | | [required] | 205 | | **page_size** | Option<**i64**> | | | 206 | | **page_number** | Option<**i64**> | | | 207 | | **include_orgs** | Option<**bool**> | Defaults to false | | 208 | 209 | ### Return type 210 | 211 | [**crate::models::UserPagedResponse**](UserPagedResponse.md) 212 | 213 | ### Authorization 214 | 215 | [BearerAuth](../README.md#BearerAuth) 216 | 217 | ### HTTP request headers 218 | 219 | - **Content-Type**: Not defined 220 | - **Accept**: application/json 221 | 222 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 223 | 224 | ## remove_user_from_org 225 | 226 | > crate::models::SuccessfulResponse remove_user_from_org(remove_user_from_org_request) 227 | 228 | ### Parameters 229 | 230 | | Name | Type | Description | Required | Notes | 231 | | -------------------------------- | ----------------------------------------------------------- | ----------- | ---------- | ----- | 232 | | **remove_user_from_org_request** | [**RemoveUserFromOrgRequest**](RemoveUserFromOrgRequest.md) | | [required] | 233 | 234 | ### Return type 235 | 236 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 237 | 238 | ### Authorization 239 | 240 | [BearerAuth](../README.md#BearerAuth) 241 | 242 | ### HTTP request headers 243 | 244 | - **Content-Type**: application/json 245 | - **Accept**: application/json 246 | 247 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 248 | 249 | ## update_org 250 | 251 | > crate::models::SuccessfulResponse update_org(org_id, update_org_request) 252 | 253 | ### Parameters 254 | 255 | | Name | Type | Description | Required | Notes | 256 | | ---------------------- | ------------------------------------------- | ----------- | ---------- | ----- | 257 | | **org_id** | **String** | | [required] | 258 | | **update_org_request** | [**UpdateOrgRequest**](UpdateOrgRequest.md) | | [required] | 259 | 260 | ### Return type 261 | 262 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 263 | 264 | ### Authorization 265 | 266 | [BearerAuth](../README.md#BearerAuth) 267 | 268 | ### HTTP request headers 269 | 270 | - **Content-Type**: application/json 271 | - **Accept**: application/json 272 | 273 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 274 | 275 | ## delete_org 276 | 277 | > crate::models::SuccessfulResponse delete_org(org_id) 278 | 279 | ### Parameters 280 | 281 | | Name | Type | Description | Required | Notes | 282 | | ---------- | ---------- | ----------- | ---------- | ----- | 283 | | **org_id** | **String** | | [required] | 284 | 285 | ### Return type 286 | 287 | [**crate::models::SuccessfulResponse**](SuccessfulResponse.md) 288 | 289 | ### Authorization 290 | 291 | [BearerAuth](../README.md#BearerAuth) 292 | 293 | ### HTTP request headers 294 | 295 | - **Content-Type**: Not defined 296 | - **Accept**: application/json 297 | 298 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) 299 | --------------------------------------------------------------------------------