-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix timestamp mapping * Add deprecated response structs * Add deprecated API * Add tests
- Loading branch information
1 parent
b356821
commit 4a206eb
Showing
13 changed files
with
545 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
defmodule WorkOS.MFA do | ||
@moduledoc """ | ||
This module is deprecated. | ||
""" | ||
|
||
@deprecated "MFA has been replaced by the User Management Multi-Factor API." | ||
|
||
alias WorkOS.Empty | ||
alias WorkOS.MFA.AuthenticationFactor | ||
alias WorkOS.MFA.AuthenticationChallenge | ||
alias WorkOS.MFA.VerifyChallenge | ||
|
||
@doc """ | ||
Enrolls an Authentication Factor. | ||
Parameter options: | ||
* `:type` - The type of the factor to enroll. Only option available is `totp`. (required) | ||
* `:totp_issuer` - For `totp` factors. Typically your application or company name, this helps users distinguish between factors in authenticator apps. | ||
* `:totp_user` - For `totp` factors. Used as the account name in authenticator apps. Defaults to the user's email. | ||
* `:phone_number` - A valid phone number for an SMS-enabled device. Required when type is sms. | ||
""" | ||
@spec enroll_factor(map()) :: WorkOS.Client.response(AuthenticationFactor.t()) | ||
@spec enroll_factor(WorkOS.Client.t(), map()) :: | ||
WorkOS.Client.response(AuthenticationFactor.t()) | ||
def enroll_factor(client \\ WorkOS.client(), opts) when is_map_key(opts, :type) do | ||
WorkOS.Client.post( | ||
client, | ||
AuthenticationFactor, | ||
"/auth/factors/enroll", | ||
%{ | ||
type: opts[:type], | ||
totp_issuer: opts[:totp_issuer], | ||
totp_user: opts[:totp_user], | ||
phone_number: opts[:phone_number] | ||
} | ||
) | ||
end | ||
|
||
@doc """ | ||
Creates a Challenge for an Authentication Factor. | ||
Parameter options: | ||
* `:sms_template` - A valid phone number for an SMS-enabled device. Required when type is sms. | ||
""" | ||
@spec challenge_factor(String.t(), map()) :: WorkOS.Client.response(AuthenticationChallenge.t()) | ||
@spec challenge_factor(WorkOS.Client.t(), String.t(), map()) :: | ||
WorkOS.Client.response(AuthenticationChallenge.t()) | ||
def challenge_factor(client \\ WorkOS.client(), authentication_factor_id, opts) do | ||
WorkOS.Client.post( | ||
client, | ||
AuthenticationChallenge, | ||
"/auth/factors/:id/challenge", | ||
%{ | ||
sms_template: opts[:sms_template] | ||
}, | ||
opts: [ | ||
path_params: [id: authentication_factor_id] | ||
] | ||
) | ||
end | ||
|
||
@doc """ | ||
Verifies Authentication Challenge. | ||
Parameter options: | ||
* `:code` - The 6 digit code to be verified. (required) | ||
""" | ||
@spec verify_challenge(String.t(), map()) :: WorkOS.Client.response(VerifyChallenge.t()) | ||
@spec verify_challenge(WorkOS.Client.t(), String.t(), map()) :: | ||
WorkOS.Client.response(VerifyChallenge.t()) | ||
def verify_challenge(client \\ WorkOS.client(), authentication_challenge_id, opts) | ||
when is_map_key(opts, :code) do | ||
WorkOS.Client.post( | ||
client, | ||
VerifyChallenge, | ||
"/auth/challenges/:id/verify", | ||
%{ | ||
code: opts[:code] | ||
}, | ||
opts: [ | ||
path_params: [id: authentication_challenge_id] | ||
] | ||
) | ||
end | ||
|
||
@doc """ | ||
Gets an Authentication Factor. | ||
""" | ||
@spec get_factor(String.t()) :: | ||
WorkOS.Client.response(AuthenticationFactor.t()) | ||
@spec get_factor(WorkOS.Client.t(), String.t()) :: | ||
WorkOS.Client.response(AuthenticationFactor.t()) | ||
def get_factor(client \\ WorkOS.client(), authentication_factor_id) do | ||
WorkOS.Client.get( | ||
client, | ||
AuthenticationFactor, | ||
"/auth/factors/:id", | ||
opts: [ | ||
path_params: [id: authentication_factor_id] | ||
] | ||
) | ||
end | ||
|
||
@doc """ | ||
Deletes an Authentication Factor. | ||
""" | ||
@spec delete_factor(String.t()) :: WorkOS.Client.response(nil) | ||
@spec delete_factor(WorkOS.Client.t(), String.t()) :: WorkOS.Client.response(nil) | ||
def delete_factor(client \\ WorkOS.client(), authentication_factor_id) do | ||
WorkOS.Client.delete(client, Empty, "/auth/factors/:id", %{}, | ||
opts: [ | ||
path_params: [id: authentication_factor_id] | ||
] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule WorkOS.MFA.AuthenticationChallenge do | ||
@moduledoc """ | ||
This response struct is deprecated. Use the User Management Multi-Factor API instead. | ||
""" | ||
|
||
@behaviour WorkOS.Castable | ||
|
||
@type t() :: %__MODULE__{ | ||
id: String.t(), | ||
authentication_factor_id: String.t(), | ||
expires_at: String.t(), | ||
updated_at: String.t(), | ||
created_at: String.t() | ||
} | ||
|
||
@enforce_keys [:id, :authentication_factor_id, :expires_at, :updated_at, :created_at] | ||
defstruct [ | ||
:id, | ||
:authentication_factor_id, | ||
:expires_at, | ||
:updated_at, | ||
:created_at | ||
] | ||
|
||
@impl true | ||
def cast(map) do | ||
%__MODULE__{ | ||
id: map["id"], | ||
authentication_factor_id: map["authentication_factor_id"], | ||
expires_at: map["expires_at"], | ||
updated_at: map["updated_at"], | ||
created_at: map["created_at"] | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule WorkOS.MFA.AuthenticationFactor do | ||
@moduledoc """ | ||
This response struct is deprecated. Use the User Management Multi-Factor API instead. | ||
""" | ||
|
||
@behaviour WorkOS.Castable | ||
|
||
alias WorkOS.MFA.SMS | ||
alias WorkOS.MFA.TOTP | ||
|
||
@type t() :: %__MODULE__{ | ||
id: String.t(), | ||
type: String.t(), | ||
sms: SMS.t() | nil, | ||
totp: TOTP.t() | nil, | ||
updated_at: String.t(), | ||
created_at: String.t() | ||
} | ||
|
||
@enforce_keys [:id, :type, :sms, :totp, :updated_at, :created_at] | ||
defstruct [ | ||
:id, | ||
:type, | ||
:sms, | ||
:totp, | ||
:updated_at, | ||
:created_at | ||
] | ||
|
||
@impl true | ||
def cast(map) do | ||
%__MODULE__{ | ||
id: map["id"], | ||
type: map["type"], | ||
sms: map["sms"], | ||
totp: map["totp"], | ||
updated_at: map["updated_at"], | ||
created_at: map["created_at"] | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule WorkOS.MFA.SMS do | ||
@moduledoc """ | ||
This response struct is deprecated. Use the User Management Multi-Factor API instead. | ||
""" | ||
|
||
@behaviour WorkOS.Castable | ||
|
||
@type t() :: %__MODULE__{ | ||
phone_number: String.t() | ||
} | ||
|
||
@enforce_keys [ | ||
:phone_number | ||
] | ||
defstruct [ | ||
:phone_number | ||
] | ||
|
||
@impl true | ||
def cast(map) do | ||
%__MODULE__{ | ||
phone_number: map["phone_number"] | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule WorkOS.MFA.TOTP do | ||
@moduledoc """ | ||
This response struct is deprecated. Use the User Management Multi-Factor API instead. | ||
""" | ||
|
||
@behaviour WorkOS.Castable | ||
|
||
@type t() :: %__MODULE__{ | ||
issuer: String.t(), | ||
user: String.t(), | ||
secret: String.t(), | ||
qr_code: String.t(), | ||
uri: String.t() | ||
} | ||
|
||
@enforce_keys [ | ||
:issuer, | ||
:user, | ||
:secret, | ||
:qr_code, | ||
:uri | ||
] | ||
defstruct [ | ||
:issuer, | ||
:user, | ||
:secret, | ||
:qr_code, | ||
:uri | ||
] | ||
|
||
@impl true | ||
def cast(map) do | ||
%__MODULE__{ | ||
issuer: map["issuer"], | ||
user: map["user"], | ||
secret: map["secret"], | ||
qr_code: map["qr_code"], | ||
uri: map["uri"] | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule WorkOS.MFA.VerifyChallenge do | ||
@moduledoc """ | ||
This response struct is deprecated. Use the User Management Multi-Factor API instead. | ||
""" | ||
|
||
@behaviour WorkOS.Castable | ||
|
||
alias WorkOS.MFA.AuthenticationChallenge | ||
|
||
@type t() :: %__MODULE__{ | ||
challenge: AuthenticationChallenge.t(), | ||
valid: boolean() | ||
} | ||
|
||
@enforce_keys [:challenge, :valid] | ||
defstruct [ | ||
:challenge, | ||
:valid | ||
] | ||
|
||
@impl true | ||
def cast(map) do | ||
%__MODULE__{ | ||
challenge: map["challenge"], | ||
valid: map["valid"] | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.