Skip to content

Commit

Permalink
Add Sign in With Ethereum (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-stytch authored Aug 1, 2024
1 parent da1d6a3 commit c2cf018
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/stytch/b2b_organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def dangerously_get(
# 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 then to be subsequently re-used by other Organization Members. Retired email addresses can be viewed
# addresses allows them to be subsequently re-used by other Organization Members. Retired email addresses can be viewed
# on the [Member object](https://stytch.com/docs/b2b/api/member-object).
# %}
#
Expand Down
2 changes: 1 addition & 1 deletion lib/stytch/b2b_scim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def initialize(connection)
# (no documentation yet)
# The type of this field is nilable +UpdateRequestIdentityProvider+ (string enum).
# scim_group_implicit_role_assignments::
# (no documentation yet)
# An array of SCIM group implicit role assignments. Each object in the array must contain a `group` and a `role_id`.
# The type of this field is nilable list of +SCIMGroupImplicitRoleAssignments+.
#
# == Returns:
Expand Down
17 changes: 15 additions & 2 deletions lib/stytch/crypto_wallets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def initialize(connection)
@connection = connection
end

# Initiate the authentication of a crypto wallet. After calling this endpoint, the user will need to sign a message containing only the returned `challenge` field.
# Initiate the authentication of a crypto wallet. After calling this endpoint, the user will need to sign a message containing the returned `challenge` field.
#
# For Ethereum crypto wallets, you can optionally use the Sign In With Ethereum (SIWE) protocol for the message by passing in the `siwe_params`. The only required fields are `domain` and `uri`.
# If the crypto wallet detects that the domain in the message does not match the website's domain, it will display a warning to the user.
#
# If not using the SIWE protocol, the message will simply consist of the project name and a random string.
#
# == Parameters:
# crypto_wallet_type::
Expand All @@ -34,6 +39,9 @@ def initialize(connection)
# session_jwt::
# The `session_jwt` associated with a User's existing Session.
# The type of this field is nilable +String+.
# siwe_params::
# The parameters for a Sign In With Ethereum (SIWE) message. May only be passed if the `crypto_wallet_type` is `ethereum`.
# The type of this field is nilable +SIWEParams+ (+object+).
#
# == Returns:
# An object with the following fields:
Expand All @@ -57,7 +65,8 @@ def authenticate_start(
crypto_wallet_address:,
user_id: nil,
session_token: nil,
session_jwt: nil
session_jwt: nil,
siwe_params: nil
)
headers = {}
request = {
Expand All @@ -67,6 +76,7 @@ def authenticate_start(
request[:user_id] = user_id unless user_id.nil?
request[:session_token] = session_token unless session_token.nil?
request[:session_jwt] = session_jwt unless session_jwt.nil?
request[:siwe_params] = siwe_params unless siwe_params.nil?

post_request('/v1/crypto_wallets/authenticate/start', request, headers)
end
Expand Down Expand Up @@ -132,6 +142,9 @@ def authenticate_start(
# See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
#
# The type of this field is nilable +Session+ (+object+).
# siwe_params::
# The parameters of the Sign In With Ethereum (SIWE) message that was signed.
# The type of this field is nilable +SIWEParamsResponse+ (+object+).
def authenticate(
crypto_wallet_type:,
crypto_wallet_address:,
Expand Down
49 changes: 49 additions & 0 deletions lib/stytch/sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,55 @@ def revoke(
post_request('/v1/sessions/revoke', request, headers)
end

# Migrate a session from an external OIDC compliant endpoint. Stytch will call the external UserInfo endpoint defined in your Stytch Project settings in the [Dashboard](/dashboard), and then perform a lookup using the `session_token`. If the response contains a valid email address, Stytch will attempt to match that email address with an existing User and create a Stytch Session. You will need to create the user before using this endpoint.
#
# == Parameters:
# session_token::
# The `session_token` associated with a User's existing Session.
# The type of this field is +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.
# The type of this field is nilable +Integer+.
# 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.
# The type of this field is nilable +object+.
#
# == Returns:
# An object with the following fields:
# 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.
# The type of this field is +String+.
# user_id::
# The unique ID of the affected User.
# The type of this field is +String+.
# session_token::
# A secret token for a given Stytch Session.
# The type of this field is +String+.
# session_jwt::
# The JSON Web Token (JWT) for a given Stytch Session.
# The type of this field is +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.
# The type of this field is +User+ (+object+).
# status_code::
# (no documentation yet)
# The type of this field is +Integer+.
# 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.
#
# The type of this field is nilable +Session+ (+object+).
def migrate(
session_token:,
session_duration_minutes: nil,
Expand Down
2 changes: 1 addition & 1 deletion lib/stytch/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stytch
VERSION = '9.3.0'
VERSION = '9.4.0'
end

0 comments on commit c2cf018

Please sign in to comment.