Skip to content

Commit

Permalink
Add Sign in With Ethereum (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-stytch authored Aug 1, 2024
2 parents ccbe92c + 7b8528e commit 4631c94
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stytch"
version = "3.1.1"
version = "3.2.0"
edition = "2021"
license = "MIT"
description = "Stytch Rust client"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The minimum supported Rust version (MSRV) of this library is Rust 1.70.
Use `cargo add stytch` to add this to your `Cargo.toml`:

```toml
stytch = "3.1.1"
stytch = "3.2.0"
```

## Usage
Expand Down
17 changes: 17 additions & 0 deletions src/b2b/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ pub struct Member {
/// [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/stytch-default) for more details on this Role.
pub is_admin: bool,
pub totp_registration_id: String,
/// retired_email_addresses:
/// A list of retired email addresses for this member.
/// A previously active email address can be marked as retired in one of two ways:
/// - It's replaced with a new primary email address during an explicit Member update.
/// - A new email address is surfaced by an OAuth, SAML or OIDC provider. In this case the new email
/// address becomes the
/// Member's primary email address and the old primary email address is retired.
///
/// A retired email address cannot be used by other Members in the same Organization. However, unlinking
/// retired email
/// addresses allows them to be subsequently re-used by other Organization Members. Retired email
/// addresses can be unlinked
/// using the [Unlink Retired Email endpoint](https://stytch.com/docs/b2b/api/unlink-retired-member-email).
///
pub retired_email_addresses: std::vec::Vec<RetiredEmail>,
/// mfa_enrolled: Sets whether the Member is enrolled in MFA. If true, the Member must complete an MFA step
/// whenever they wish to log in to their Organization. If false, the Member only needs to complete an MFA
Expand Down Expand Up @@ -345,9 +359,12 @@ pub struct ResultsMetadata {
/// results. This value is passed into your next search call in the `cursor` field.
pub next_cursor: std::option::Option<String>,
}
/// RetiredEmail:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RetiredEmail {
/// email_id: The globally unique UUID of a Member's email.
pub email_id: String,
/// email_address: The email address of the Member.
pub email_address: String,
}
/// SCIMRegistration:
Expand Down
2 changes: 2 additions & 0 deletions src/b2b/scim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ pub struct SCIMGroup {
/// connection_id: The ID of the SCIM connection.
pub connection_id: String,
}
/// SCIMGroupImplicitRoleAssignments:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SCIMGroupImplicitRoleAssignments {
/// role_id: The ID of the role.
pub role_id: String,
pub group_id: String,
pub group_name: String,
Expand Down
2 changes: 2 additions & 0 deletions src/b2b/scim_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ pub struct UpdateRequest {
/// display_name: A human-readable display name for the connection.
pub display_name: std::option::Option<String>,
pub identity_provider: std::option::Option<UpdateRequestIdentityProvider>,
/// scim_group_implicit_role_assignments: An array of SCIM group implicit role assignments. Each object in
/// the array must contain a `group` and a `role_id`.
pub scim_group_implicit_role_assignments:
std::option::Option<std::vec::Vec<SCIMGroupImplicitRoleAssignments>>,
}
Expand Down
53 changes: 53 additions & 0 deletions src/consumer/crypto_wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@ use crate::consumer::sessions::Session;
use crate::consumer::users::User;
use serde::{Deserialize, Serialize};

/// SIWEParams:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SIWEParams {
/// domain: Only required if `siwe_params` is passed. The domain that is requesting the crypto wallet
/// signature. Must be an RFC 3986 authority.
pub domain: String,
/// uri: Only required if `siwe_params` is passed. An RFC 3986 URI referring to the resource that is the
/// subject of the signing.
pub uri: String,
/// resources: A list of information or references to information the user wishes to have resolved as part
/// of authentication. Every resource must be an RFC 3986 URI.
pub resources: std::vec::Vec<String>,
/// chain_id: The EIP-155 Chain ID to which the session is bound. Defaults to 1.
pub chain_id: std::option::Option<i32>,
/// statement: A human-readable ASCII assertion that the user will sign.
pub statement: std::option::Option<String>,
/// issued_at: The time when the message was generated. Defaults to the current time. All timestamps in our
/// API conform to the RFC 3339 standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`.
pub issued_at: std::option::Option<chrono::DateTime<chrono::Utc>>,
/// not_before: The time when the signed authentication message will become valid. Defaults to the current
/// time. All timestamps in our API conform to the RFC 3339 standard and are expressed in UTC, e.g.
/// `2021-12-29T12:33:09Z`.
pub not_before: std::option::Option<chrono::DateTime<chrono::Utc>>,
/// message_request_id: A system-specific identifier that may be used to uniquely refer to the sign-in
/// request.
pub message_request_id: std::option::Option<String>,
}
/// AuthenticateRequest: Request type for `CryptoWallets.authenticate`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AuthenticateRequest {
Expand Down Expand Up @@ -72,6 +99,8 @@ pub struct AuthenticateResponse {
/// See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
///
pub session: std::option::Option<Session>,
/// siwe_params: The parameters of the Sign In With Ethereum (SIWE) message that was signed.
pub siwe_params: std::option::Option<SIWEParamsResponse>,
}
/// AuthenticateStartRequest: Request type for `CryptoWallets.authenticate_start`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
Expand All @@ -88,6 +117,9 @@ pub struct AuthenticateStartRequest {
pub session_token: std::option::Option<String>,
/// session_jwt: The `session_jwt` associated with a User's existing Session.
pub session_jwt: std::option::Option<String>,
/// siwe_params: The parameters for a Sign In With Ethereum (SIWE) message. May only be passed if the
/// `crypto_wallet_type` is `ethereum`.
pub siwe_params: std::option::Option<SIWEParams>,
}
/// AuthenticateStartResponse: Response type for `CryptoWallets.authenticate_start`.
#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -109,6 +141,27 @@ pub struct AuthenticateStartResponse {
#[serde(with = "http_serde::status_code")]
pub status_code: http::StatusCode,
}
/// SIWEParamsResponse:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SIWEParamsResponse {
/// domain: The domain that requested the crypto wallet signature.
pub domain: String,
/// uri: An RFC 3986 URI referring to the resource that is the subject of the signing.
pub uri: String,
/// chain_id: The EIP-155 Chain ID to which the session is bound.
pub chain_id: u32,
/// resources: A list of information or references to information the user wishes to have resolved as part
/// of authentication. Every resource must be an RFC 3986 URI.
pub resources: std::vec::Vec<String>,
#[serde(with = "http_serde::status_code")]
pub status_code: http::StatusCode,
/// issued_at: The time when the message was generated. All timestamps in our API conform to the RFC 3339
/// standard and are expressed in UTC, e.g. `2021-12-29T12:33:09Z`.
pub issued_at: std::option::Option<chrono::DateTime<chrono::Utc>>,
/// message_request_id: A system-specific identifier that may be used to uniquely refer to the sign-in
/// request.
pub message_request_id: std::option::Option<String>,
}

pub struct CryptoWallets {
http_client: crate::client::Client,
Expand Down
35 changes: 35 additions & 0 deletions src/consumer/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,56 @@ pub struct GetResponse {
#[serde(with = "http_serde::status_code")]
pub status_code: http::StatusCode,
}
/// MigrateRequest: Request type for `Sessions.migrate`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct MigrateRequest {
/// session_token: The `session_token` associated with a User's existing Session.
pub session_token: String,
/// session_duration_minutes: Set the session lifetime to be this many minutes from now. This will start a
/// new session if one doesn't already exist,
/// returning both an opaque `session_token` and `session_jwt` for this session. Remember that the
/// `session_jwt` will have a fixed lifetime of
/// five minutes regardless of the underlying session duration, and will need to be refreshed over time.
///
/// This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
///
/// If a `session_token` or `session_jwt` is provided then a successful authentication will continue to
/// extend the session this many minutes.
///
/// If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
pub session_duration_minutes: std::option::Option<i32>,
/// session_custom_claims: Add a custom claims map to the Session being authenticated. Claims are only
/// created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be
/// included on the Session object and in the JWT. To update a key in an existing Session, supply a new
/// value. To delete a key, supply a null value.
///
/// Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be
/// ignored. Total custom claims size cannot exceed four kilobytes.
pub session_custom_claims: std::option::Option<serde_json::Value>,
}
/// MigrateResponse: Response type for `Sessions.migrate`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MigrateResponse {
/// request_id: Globally unique UUID that is returned with every API call. This value is important to log
/// for debugging purposes; we may ask for this value to help identify a specific API call when helping you
/// debug an issue.
pub request_id: String,
/// user_id: The unique ID of the affected User.
pub user_id: String,
/// session_token: A secret token for a given Stytch Session.
pub session_token: String,
/// session_jwt: The JSON Web Token (JWT) for a given Stytch Session.
pub session_jwt: String,
/// user: The `user` object affected by this API call. See the
/// [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
pub user: User,
#[serde(with = "http_serde::status_code")]
pub status_code: http::StatusCode,
/// session: If you initiate a Session, by including `session_duration_minutes` in your authenticate call,
/// you'll receive a full Session object in the response.
///
/// See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
///
pub session: std::option::Option<Session>,
}
/// RevokeRequest: Request type for `Sessions.revoke`.
Expand Down

0 comments on commit 4631c94

Please sign in to comment.