stytch 0.2.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODEOWNERS +7 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/DEVELOPMENT.md +18 -0
- data/Gemfile +4 -2
- data/README.md +48 -10
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/stytch.rb +2 -0
- data/lib/stytch/client.rb +17 -50
- data/lib/stytch/magic_links.rb +117 -0
- data/lib/stytch/middleware.rb +4 -2
- data/lib/stytch/otps.rb +121 -0
- data/lib/stytch/request_helper.rb +43 -0
- data/lib/stytch/users.rb +100 -0
- data/lib/stytch/version.rb +3 -1
- data/stytch.gemspec +14 -12
- metadata +10 -7
- data/lib/stytch/endpoints/magic.rb +0 -111
- data/lib/stytch/endpoints/otp.rb +0 -56
- data/lib/stytch/endpoints/user.rb +0 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f10d2ac983b6812590a7d1d01fa649ea9a84bcdbff28cdc34b47dc6e075ebcaf
|
4
|
+
data.tar.gz: '08dbadda02435370eceb0d66533a11631c05ab615e646a0d6fa77d58fb579bdb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d084490ad18ef02b1f9215356be00e987379b773652a42c22e95058ff38631e8d0d020a93361f1b70c56041451d25e71daf3e6b896e27022185d46045b4fdd0
|
7
|
+
data.tar.gz: e62da9085f0263fe06c5134747f2b5a5992d6163333a90197e1ab0e1aa2379e7a8d73124fe2d93c443ca1431d36447b64735e2086edc1e73eebfd359b33e8d25
|
data/CODEOWNERS
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Stytch code owners file
|
2
|
+
|
3
|
+
# These owners will be the default owners for everything in
|
4
|
+
# the repo. Unless a later match takes precedence,
|
5
|
+
# @stytchauth/client-libraries will be requested for
|
6
|
+
# review when someone opens a pull request.
|
7
|
+
* @stytchauth/client-libraries
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at support@stytch.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/DEVELOPMENT.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Development
|
2
|
+
|
3
|
+
Thanks for contributing to Stytch's Ruby library! If you run into trouble, find us in [Slack].
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
1. Clone this repo.
|
8
|
+
2. To test your changes locally, update your GEMFILE with `gem 'stytch', path: '../stytch'` where `../stytch` is the path to your cloned copy of stytch-ruby.
|
9
|
+
|
10
|
+
## Issues and Pull Requests
|
11
|
+
|
12
|
+
Please file issues in this repo. We don't have an issue template yet, but for now, say whatever you think is important!
|
13
|
+
|
14
|
+
If you have non-trivial changes you'd like us to incorporate, please open an issue first so we can discuss the changes before starting on a pull request. (It's fine to start with the PR for a typo or simple bug.) If we think the changes align with the direction of the project, we'll either ask you to open the PR or assign someone on the Stytch team to make the changes.
|
15
|
+
|
16
|
+
When you're ready for someone to look at your issue or PR, assign `@stytchauth/client-libraries` (GitHub should do this automatically). If we don't acknowledge it within one business day, please escalate it by tagging `@stytchauth/engineering` in a comment or letting us know in [Slack].
|
17
|
+
|
18
|
+
[Slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
# Stytch
|
1
|
+
# Stytch Ruby Gem
|
2
2
|
|
3
|
-
|
3
|
+
The Stytch Ruby gem makes it easy to use the Stytch user infrastructure API in Ruby applications.
|
4
4
|
|
5
|
-
|
5
|
+
It pairs well with the Stytch [Web SDK](https://www.npmjs.com/package/@stytch/stytch-js) or your own custom authentication flow.
|
6
|
+
|
7
|
+
## Install
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
@@ -20,25 +22,61 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
You can find your API credentials in the [Stytch Dashboard](https://stytch.com/dashboard/api-keys).
|
26
|
+
|
27
|
+
Create an API client:
|
28
|
+
```ruby
|
26
29
|
client = Stytch::Client.new(
|
27
|
-
env: :test,
|
30
|
+
env: :test, # available environments are :test and :live
|
28
31
|
project_id: "***",
|
29
32
|
secret: "***"
|
30
33
|
)
|
31
34
|
```
|
32
35
|
|
33
|
-
|
36
|
+
Send a magic link by email:
|
37
|
+
```ruby
|
38
|
+
client.magic_links.email.login_or_create(
|
39
|
+
email: "sandbox@stytch.com",
|
40
|
+
login_magic_link_url: "https://example.com/login",
|
41
|
+
signup_magic_link_url: "https://example.com/signup",
|
42
|
+
)
|
34
43
|
```
|
35
|
-
|
44
|
+
|
45
|
+
Authenticate the token from the magic link:
|
46
|
+
```ruby
|
47
|
+
client.magic_links.authenticate(
|
48
|
+
token: "DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=",
|
49
|
+
)
|
36
50
|
```
|
37
51
|
|
52
|
+
## Handling Errors
|
53
|
+
|
54
|
+
When possible the response will contain an `error_type` and an `error_message` that can be used to distinguish errors.
|
55
|
+
|
56
|
+
Learn more about errors in the [docs](https://stytch.com/docs/api/errors).
|
57
|
+
|
58
|
+
## Documentation
|
59
|
+
|
60
|
+
See example requests and responses for all the endpoints in the [Stytch API Reference](https://stytch.com/docs/api).
|
61
|
+
|
62
|
+
Follow one of the [integration guides](https://stytch.com/docs/guides) or start with one of our [example apps](https://stytch.com/docs/example-apps).
|
63
|
+
|
64
|
+
## Support
|
65
|
+
|
66
|
+
If you've found a bug, [open an issue](https://github.com/stytchauth/stytch-ruby/issues/new)!
|
67
|
+
|
68
|
+
If you have questions or want help troubleshooting, join us in [Slack](https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg) or email support@stytch.com.
|
69
|
+
|
70
|
+
If you've found a security vulnerability, please follow our [responsible disclosure instructions](https://stytch.com/docs/security).
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
See [DEVELOPMENT.md](DEVELOPMENT.md)
|
75
|
+
|
38
76
|
## License
|
39
77
|
|
40
78
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
79
|
|
42
80
|
## Code of Conduct
|
43
81
|
|
44
|
-
Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](
|
82
|
+
Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'stytch'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "stytch"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/stytch.rb
CHANGED
data/lib/stytch/client.rb
CHANGED
@@ -1,30 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative '
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'users'
|
4
|
+
require_relative 'magic_links'
|
5
|
+
require_relative 'otps'
|
4
6
|
|
5
7
|
module Stytch
|
6
8
|
class Client
|
7
|
-
include Stytch::Endpoints::User
|
8
|
-
include Stytch::Endpoints::Magic
|
9
|
-
include Stytch::Endpoints::OTP
|
10
|
-
|
11
9
|
ENVIRONMENTS = %i[live test].freeze
|
12
10
|
|
11
|
+
attr_reader :users, :magic_links, :otps
|
12
|
+
|
13
13
|
def initialize(env:, project_id:, secret:, &block)
|
14
14
|
@api_host = api_host(env)
|
15
|
-
@project_id
|
15
|
+
@project_id = project_id
|
16
16
|
@secret = secret
|
17
17
|
|
18
18
|
create_connection(&block)
|
19
|
+
|
20
|
+
@users = Stytch::Users.new(@connection)
|
21
|
+
@magic_links = Stytch::MagicLinks.new(@connection)
|
22
|
+
@otps = Stytch::OTPs.new(@connection)
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
26
|
|
23
27
|
def api_host(env)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
case env
|
29
|
+
when :live
|
30
|
+
'https://api.stytch.com'
|
31
|
+
when :test
|
32
|
+
'https://test.stytch.com'
|
28
33
|
else
|
29
34
|
raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
|
30
35
|
end
|
@@ -45,43 +50,5 @@ module Stytch
|
|
45
50
|
builder.response :json, content_type: /\bjson$/
|
46
51
|
builder.adapter Faraday.default_adapter
|
47
52
|
end
|
48
|
-
|
49
|
-
def get(path)
|
50
|
-
@connection.get(
|
51
|
-
path
|
52
|
-
).body
|
53
|
-
end
|
54
|
-
|
55
|
-
def post(path, payload)
|
56
|
-
@connection.post(
|
57
|
-
path,
|
58
|
-
payload
|
59
|
-
).body
|
60
|
-
end
|
61
|
-
|
62
|
-
def put(path, payload)
|
63
|
-
@connection.put(
|
64
|
-
path,
|
65
|
-
payload
|
66
|
-
).body
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete(path)
|
70
|
-
@connection.delete(
|
71
|
-
path
|
72
|
-
).body
|
73
|
-
end
|
74
|
-
|
75
|
-
def request_with_query_params(path, params)
|
76
|
-
request = path
|
77
|
-
params.compact.each_with_index do |p, i|
|
78
|
-
if i == 0
|
79
|
-
request += "?#{p[0].to_s}=#{p[1]}"
|
80
|
-
else
|
81
|
-
request += "&#{p[0].to_s}=#{p[1]}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
request
|
85
|
-
end
|
86
53
|
end
|
87
54
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class MagicLinks
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
attr_reader :email
|
10
|
+
|
11
|
+
PATH = '/v1/magic_links'
|
12
|
+
|
13
|
+
def initialize(connection)
|
14
|
+
@connection = connection
|
15
|
+
|
16
|
+
@email = Stytch::MagicLinks::Email.new(@connection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate(
|
20
|
+
token:,
|
21
|
+
attributes: {},
|
22
|
+
options: {}
|
23
|
+
)
|
24
|
+
request = {
|
25
|
+
token: token
|
26
|
+
}
|
27
|
+
|
28
|
+
request[:attributes] = attributes if attributes != {}
|
29
|
+
request[:options] = options if options != {}
|
30
|
+
|
31
|
+
post_request("#{PATH}/authenticate", request)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Email
|
35
|
+
include Stytch::RequestHelper
|
36
|
+
|
37
|
+
PATH = "#{Stytch::MagicLinks::PATH}/email"
|
38
|
+
|
39
|
+
def initialize(connection)
|
40
|
+
@connection = connection
|
41
|
+
end
|
42
|
+
|
43
|
+
def send(
|
44
|
+
email:,
|
45
|
+
login_magic_link_url:,
|
46
|
+
signup_magic_link_url:,
|
47
|
+
login_expiration_minutes: nil,
|
48
|
+
signup_expiration_minutes: nil,
|
49
|
+
attributes: {}
|
50
|
+
)
|
51
|
+
request = {
|
52
|
+
email: email,
|
53
|
+
login_magic_link_url: login_magic_link_url,
|
54
|
+
signup_magic_link_url: signup_magic_link_url
|
55
|
+
}
|
56
|
+
|
57
|
+
request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
|
58
|
+
request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
|
59
|
+
request[:attributes] = attributes if attributes != {}
|
60
|
+
|
61
|
+
post_request("#{PATH}/send", request)
|
62
|
+
end
|
63
|
+
|
64
|
+
def login_or_create(
|
65
|
+
email:,
|
66
|
+
login_magic_link_url:,
|
67
|
+
signup_magic_link_url:,
|
68
|
+
login_expiration_minutes: nil,
|
69
|
+
signup_expiration_minutes: nil,
|
70
|
+
attributes: {},
|
71
|
+
create_user_as_pending: false
|
72
|
+
)
|
73
|
+
request = {
|
74
|
+
email: email,
|
75
|
+
login_magic_link_url: login_magic_link_url,
|
76
|
+
signup_magic_link_url: signup_magic_link_url,
|
77
|
+
create_user_as_pending: create_user_as_pending
|
78
|
+
}
|
79
|
+
|
80
|
+
request[:login_expiration_minutes] = login_expiration_minutes unless login_expiration_minutes.nil?
|
81
|
+
request[:signup_expiration_minutes] = signup_expiration_minutes unless signup_expiration_minutes.nil?
|
82
|
+
request[:attributes] = attributes if attributes != {}
|
83
|
+
|
84
|
+
post_request("#{PATH}/login_or_create", request)
|
85
|
+
end
|
86
|
+
|
87
|
+
def invite(
|
88
|
+
email:,
|
89
|
+
invite_magic_link_url:,
|
90
|
+
invite_expiration_minutes: nil,
|
91
|
+
attributes: {},
|
92
|
+
name: {}
|
93
|
+
)
|
94
|
+
request = {
|
95
|
+
email: email,
|
96
|
+
invite_magic_link_url: invite_magic_link_url
|
97
|
+
}
|
98
|
+
|
99
|
+
request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?
|
100
|
+
request[:attributes] = attributes if attributes != {}
|
101
|
+
request[:name] = name if name != {}
|
102
|
+
|
103
|
+
post_request("#{PATH}/invite", request)
|
104
|
+
end
|
105
|
+
|
106
|
+
def revoke_invite(
|
107
|
+
email:
|
108
|
+
)
|
109
|
+
request = {
|
110
|
+
email: email
|
111
|
+
}
|
112
|
+
|
113
|
+
post_request("#{PATH}/revoke_invite", request)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/stytch/middleware.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'net/http'
|
3
5
|
require 'uri'
|
@@ -7,8 +9,8 @@ require_relative 'version'
|
|
7
9
|
module Stytch
|
8
10
|
class Middleware < ::Faraday::Response::Middleware
|
9
11
|
NETWORK_HEADERS = {
|
10
|
-
'User-Agent'
|
11
|
-
'Content-Type'
|
12
|
+
'User-Agent' => "Stytch Ruby v#{Stytch::VERSION}",
|
13
|
+
'Content-Type' => 'application/json'
|
12
14
|
}.freeze
|
13
15
|
|
14
16
|
NETWORK_TIMEOUT = 300
|
data/lib/stytch/otps.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class OTPs
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
attr_reader :sms, :whatsapp
|
10
|
+
|
11
|
+
PATH = '/v1/otps'
|
12
|
+
|
13
|
+
def initialize(connection)
|
14
|
+
@connection = connection
|
15
|
+
|
16
|
+
@sms = Stytch::OTPs::SMS.new(@connection)
|
17
|
+
@whatsapp = Stytch::OTPs::WhatsApp.new(@connection)
|
18
|
+
end
|
19
|
+
|
20
|
+
def authenticate(
|
21
|
+
method_id:,
|
22
|
+
code:,
|
23
|
+
attributes: {},
|
24
|
+
options: {}
|
25
|
+
)
|
26
|
+
request = {
|
27
|
+
method_id: method_id,
|
28
|
+
code: code
|
29
|
+
}
|
30
|
+
|
31
|
+
request[:attributes] = attributes if attributes != {}
|
32
|
+
request[:options] = options if options != {}
|
33
|
+
|
34
|
+
post_request("#{PATH}/authenticate", request)
|
35
|
+
end
|
36
|
+
|
37
|
+
class SMS
|
38
|
+
include Stytch::RequestHelper
|
39
|
+
|
40
|
+
PATH = "#{Stytch::OTPs::PATH}/sms"
|
41
|
+
|
42
|
+
def initialize(connection)
|
43
|
+
@connection = connection
|
44
|
+
end
|
45
|
+
|
46
|
+
def send(
|
47
|
+
phone_number:,
|
48
|
+
expiration_minutes: nil,
|
49
|
+
attributes: {}
|
50
|
+
)
|
51
|
+
request = {
|
52
|
+
phone_number: phone_number,
|
53
|
+
expiration_minutes: expiration_minutes
|
54
|
+
}
|
55
|
+
|
56
|
+
request[:attributes] = attributes if attributes != {}
|
57
|
+
|
58
|
+
post_request("#{PATH}/send", request)
|
59
|
+
end
|
60
|
+
|
61
|
+
def login_or_create(
|
62
|
+
phone_number:,
|
63
|
+
expiration_minutes: nil,
|
64
|
+
attributes: {},
|
65
|
+
create_user_as_pending: false
|
66
|
+
)
|
67
|
+
request = {
|
68
|
+
phone_number: phone_number,
|
69
|
+
expiration_minutes: expiration_minutes,
|
70
|
+
create_user_as_pending: create_user_as_pending
|
71
|
+
}
|
72
|
+
|
73
|
+
request[:attributes] = attributes if attributes != {}
|
74
|
+
|
75
|
+
post_request("#{PATH}/login_or_create", request)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class WhatsApp
|
80
|
+
include Stytch::RequestHelper
|
81
|
+
|
82
|
+
PATH = "#{Stytch::OTPs::PATH}/whatsapp"
|
83
|
+
|
84
|
+
def initialize(connection)
|
85
|
+
@connection = connection
|
86
|
+
end
|
87
|
+
|
88
|
+
def send(
|
89
|
+
phone_number:,
|
90
|
+
expiration_minutes: nil,
|
91
|
+
attributes: {}
|
92
|
+
)
|
93
|
+
request = {
|
94
|
+
phone_number: phone_number,
|
95
|
+
expiration_minutes: expiration_minutes
|
96
|
+
}
|
97
|
+
|
98
|
+
request[:attributes] = attributes if attributes != {}
|
99
|
+
|
100
|
+
post_request("#{PATH}/send", request)
|
101
|
+
end
|
102
|
+
|
103
|
+
def login_or_create(
|
104
|
+
phone_number:,
|
105
|
+
expiration_minutes: nil,
|
106
|
+
attributes: {},
|
107
|
+
create_user_as_pending: false
|
108
|
+
)
|
109
|
+
request = {
|
110
|
+
phone_number: phone_number,
|
111
|
+
expiration_minutes: expiration_minutes,
|
112
|
+
create_user_as_pending: create_user_as_pending
|
113
|
+
}
|
114
|
+
|
115
|
+
request[:attributes] = attributes if attributes != {}
|
116
|
+
|
117
|
+
post_request("#{PATH}/login_or_create", request)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stytch
|
4
|
+
module RequestHelper
|
5
|
+
def get_request(path)
|
6
|
+
@connection.get(
|
7
|
+
path
|
8
|
+
).body
|
9
|
+
end
|
10
|
+
|
11
|
+
def post_request(path, payload)
|
12
|
+
@connection.post(
|
13
|
+
path,
|
14
|
+
payload
|
15
|
+
).body
|
16
|
+
end
|
17
|
+
|
18
|
+
def put_request(path, payload)
|
19
|
+
@connection.put(
|
20
|
+
path,
|
21
|
+
payload
|
22
|
+
).body
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_request(path)
|
26
|
+
@connection.delete(
|
27
|
+
path
|
28
|
+
).body
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_with_query_params(path, params)
|
32
|
+
request = path
|
33
|
+
params.compact.each_with_index do |p, i|
|
34
|
+
request += if i.zero?
|
35
|
+
"?#{p[0]}=#{p[1]}"
|
36
|
+
else
|
37
|
+
"&#{p[0]}=#{p[1]}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
request
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/stytch/users.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class Users
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
PATH = '/v1/users'
|
10
|
+
|
11
|
+
def initialize(connection)
|
12
|
+
@connection = connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(user_id:)
|
16
|
+
get_request("#{PATH}/#{user_id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_pending(
|
20
|
+
limit: nil,
|
21
|
+
starting_after_id: nil
|
22
|
+
)
|
23
|
+
query_params = {
|
24
|
+
limit: limit,
|
25
|
+
starting_after_id: starting_after_id
|
26
|
+
}
|
27
|
+
|
28
|
+
request = request_with_query_params("#{PATH}/pending", query_params)
|
29
|
+
|
30
|
+
get_request(request)
|
31
|
+
end
|
32
|
+
|
33
|
+
def create(
|
34
|
+
email: nil,
|
35
|
+
phone_number: nil,
|
36
|
+
name: {},
|
37
|
+
create_user_as_pending: false,
|
38
|
+
attributes: {}
|
39
|
+
)
|
40
|
+
request = {
|
41
|
+
email: email,
|
42
|
+
phone_number: phone_number,
|
43
|
+
create_user_as_pending: create_user_as_pending
|
44
|
+
}
|
45
|
+
|
46
|
+
request[:name] = name if name != {}
|
47
|
+
request[:attributes] = attributes if attributes != {}
|
48
|
+
|
49
|
+
post_request(PATH, request)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update(
|
53
|
+
user_id:,
|
54
|
+
name: {},
|
55
|
+
emails: [],
|
56
|
+
phone_numbers: [],
|
57
|
+
attributes: {}
|
58
|
+
)
|
59
|
+
request = {
|
60
|
+
emails: format_emails(emails),
|
61
|
+
phone_numbers: format_phone_numbers(phone_numbers)
|
62
|
+
}
|
63
|
+
|
64
|
+
request[:name] = name if name != {}
|
65
|
+
request[:attributes] = attributes if attributes != {}
|
66
|
+
|
67
|
+
put_request("#{PATH}/#{user_id}", request)
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete(user_id:)
|
71
|
+
delete_request("#{PATH}/#{user_id}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_email(
|
75
|
+
email_id:
|
76
|
+
)
|
77
|
+
delete_request("#{PATH}/emails/#{email_id}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete_phone_number(
|
81
|
+
phone_id:
|
82
|
+
)
|
83
|
+
delete_request("#{PATH}/phone_numbers/#{phone_id}")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def format_emails(emails)
|
89
|
+
e = []
|
90
|
+
emails.each { |email| e << { email: email } }
|
91
|
+
e
|
92
|
+
end
|
93
|
+
|
94
|
+
def format_phone_numbers(phone_numbers)
|
95
|
+
p = []
|
96
|
+
phone_numbers.each { |phone_number| p << { phone_number: phone_number } }
|
97
|
+
p
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/stytch/version.rb
CHANGED
data/stytch.gemspec
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/stytch/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'stytch'
|
5
7
|
spec.version = Stytch::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['stytch']
|
9
|
+
spec.email = ['support@stytch.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'Stytch Ruby Gem'
|
12
|
+
spec.homepage = 'https://stytch.com'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
13
15
|
|
14
|
-
spec.metadata[
|
15
|
-
spec.metadata[
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/stytchauth/stytch-ruby'
|
16
18
|
|
17
19
|
# Specify which files should be added to the gem when it is released.
|
18
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
-
spec.files
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
23
|
end
|
22
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
26
|
+
spec.require_paths = ['lib']
|
25
27
|
|
26
28
|
spec.add_dependency 'faraday', '>= 0.17.0', '< 2.0'
|
27
29
|
spec.add_dependency 'faraday_middleware', '>= 0.14.0', '< 2.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stytch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- stytch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
version: '2.0'
|
53
53
|
description:
|
54
54
|
email:
|
55
|
-
-
|
55
|
+
- support@stytch.com
|
56
56
|
executables: []
|
57
57
|
extensions: []
|
58
58
|
extra_rdoc_files: []
|
@@ -60,7 +60,9 @@ files:
|
|
60
60
|
- ".gitignore"
|
61
61
|
- ".rspec"
|
62
62
|
- ".travis.yml"
|
63
|
+
- CODEOWNERS
|
63
64
|
- CODE_OF_CONDUCT.md
|
65
|
+
- DEVELOPMENT.md
|
64
66
|
- Gemfile
|
65
67
|
- LICENSE.txt
|
66
68
|
- README.md
|
@@ -69,10 +71,11 @@ files:
|
|
69
71
|
- bin/setup
|
70
72
|
- lib/stytch.rb
|
71
73
|
- lib/stytch/client.rb
|
72
|
-
- lib/stytch/
|
73
|
-
- lib/stytch/endpoints/otp.rb
|
74
|
-
- lib/stytch/endpoints/user.rb
|
74
|
+
- lib/stytch/magic_links.rb
|
75
75
|
- lib/stytch/middleware.rb
|
76
|
+
- lib/stytch/otps.rb
|
77
|
+
- lib/stytch/request_helper.rb
|
78
|
+
- lib/stytch/users.rb
|
76
79
|
- lib/stytch/version.rb
|
77
80
|
- stytch.gemspec
|
78
81
|
homepage: https://stytch.com
|
@@ -1,111 +0,0 @@
|
|
1
|
-
module Stytch
|
2
|
-
module Endpoints
|
3
|
-
module Magic
|
4
|
-
PATH = "/v1/magic_links".freeze
|
5
|
-
|
6
|
-
def send_magic(
|
7
|
-
method_id:,
|
8
|
-
user_id:,
|
9
|
-
magic_link_url:,
|
10
|
-
expiration_minutes: nil,
|
11
|
-
attributes: {}
|
12
|
-
)
|
13
|
-
request = {
|
14
|
-
method_id: method_id,
|
15
|
-
user_id: user_id,
|
16
|
-
magic_link_url: magic_link_url,
|
17
|
-
}
|
18
|
-
|
19
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
20
|
-
request[:attributes] = attributes if attributes != {}
|
21
|
-
|
22
|
-
post("#{PATH}/send", request)
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_magic_by_email(
|
26
|
-
email:,
|
27
|
-
magic_link_url:,
|
28
|
-
expiration_minutes: nil,
|
29
|
-
attributes: {}
|
30
|
-
)
|
31
|
-
request = {
|
32
|
-
email: email,
|
33
|
-
magic_link_url: magic_link_url,
|
34
|
-
}
|
35
|
-
|
36
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
37
|
-
request[:attributes] = attributes if attributes != {}
|
38
|
-
|
39
|
-
post("#{PATH}/send_by_email", request)
|
40
|
-
end
|
41
|
-
|
42
|
-
def login_or_create_user(
|
43
|
-
email:,
|
44
|
-
login_magic_link_url:,
|
45
|
-
signup_magic_link_url:,
|
46
|
-
login_expiration_minutes: nil,
|
47
|
-
signup_expiration_minutes: nil,
|
48
|
-
attributes: {},
|
49
|
-
create_user_as_pending: false
|
50
|
-
)
|
51
|
-
|
52
|
-
request = {
|
53
|
-
email: email,
|
54
|
-
login_magic_link_url: login_magic_link_url,
|
55
|
-
signup_magic_link_url: signup_magic_link_url,
|
56
|
-
create_user_as_pending: create_user_as_pending,
|
57
|
-
}
|
58
|
-
|
59
|
-
request[:login_expiration_minutes] = login_expiration_minutes if login_expiration_minutes != nil
|
60
|
-
request[:signup_expiration_minutes] = signup_expiration_minutes if signup_expiration_minutes != nil
|
61
|
-
request[:attributes] = attributes if attributes != {}
|
62
|
-
|
63
|
-
post("#{PATH}/login_or_create", request)
|
64
|
-
end
|
65
|
-
|
66
|
-
def invite_by_email(
|
67
|
-
email:,
|
68
|
-
magic_link_url:,
|
69
|
-
expiration_minutes: nil,
|
70
|
-
attributes: {},
|
71
|
-
name: {}
|
72
|
-
)
|
73
|
-
|
74
|
-
request = {
|
75
|
-
email: email,
|
76
|
-
magic_link_url: magic_link_url,
|
77
|
-
}
|
78
|
-
|
79
|
-
request[:expiration_minutes] = expiration_minutes if expiration_minutes != nil
|
80
|
-
request[:attributes] = attributes if attributes != {}
|
81
|
-
request[:name] = name if name != {}
|
82
|
-
|
83
|
-
post("#{PATH}/invite_by_email", request)
|
84
|
-
end
|
85
|
-
|
86
|
-
def revoke_invite_by_email(
|
87
|
-
email:
|
88
|
-
)
|
89
|
-
|
90
|
-
request = {
|
91
|
-
email: email,
|
92
|
-
}
|
93
|
-
|
94
|
-
post("#{PATH}/revoke_invite", request)
|
95
|
-
end
|
96
|
-
|
97
|
-
def authenticate_magic(
|
98
|
-
token:,
|
99
|
-
attributes: {},
|
100
|
-
options: {}
|
101
|
-
)
|
102
|
-
request = {}
|
103
|
-
|
104
|
-
request[:attributes] = attributes if attributes != {}
|
105
|
-
request[:options] = options if options != {}
|
106
|
-
|
107
|
-
post("#{PATH}/#{token}/authenticate", request)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/lib/stytch/endpoints/otp.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Stytch
|
2
|
-
module Endpoints
|
3
|
-
module OTP
|
4
|
-
PATH = "/v1/otp".freeze
|
5
|
-
|
6
|
-
def send_otp_by_sms(
|
7
|
-
phone_number:,
|
8
|
-
expiration_minutes: nil,
|
9
|
-
attributes: {}
|
10
|
-
)
|
11
|
-
request = {
|
12
|
-
phone_number: phone_number,
|
13
|
-
expiration_minutes: expiration_minutes,
|
14
|
-
}
|
15
|
-
|
16
|
-
request[:attributes] = attributes if attributes != {}
|
17
|
-
|
18
|
-
post("#{PATH}/send_by_sms", request)
|
19
|
-
end
|
20
|
-
|
21
|
-
def login_or_create_user_by_sms(
|
22
|
-
phone_number:,
|
23
|
-
expiration_minutes: nil,
|
24
|
-
attributes: {},
|
25
|
-
create_user_as_pending: false
|
26
|
-
)
|
27
|
-
request = {
|
28
|
-
phone_number: phone_number,
|
29
|
-
expiration_minutes: expiration_minutes,
|
30
|
-
create_user_as_pending: create_user_as_pending
|
31
|
-
}
|
32
|
-
|
33
|
-
request[:attributes] = attributes if attributes != {}
|
34
|
-
|
35
|
-
post("#{PATH}/login_or_create", request)
|
36
|
-
end
|
37
|
-
|
38
|
-
def authenticate_otp(
|
39
|
-
method_id:,
|
40
|
-
code:,
|
41
|
-
attributes: {},
|
42
|
-
options: {}
|
43
|
-
)
|
44
|
-
request = {
|
45
|
-
method_id: method_id,
|
46
|
-
code: code,
|
47
|
-
}
|
48
|
-
|
49
|
-
request[:attributes] = attributes if attributes != {}
|
50
|
-
request[:options] = options if options != {}
|
51
|
-
|
52
|
-
post("#{PATH}/authenticate", request)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
module Stytch
|
2
|
-
module Endpoints
|
3
|
-
module User
|
4
|
-
PATH = "/v1/users".freeze
|
5
|
-
|
6
|
-
def get_user(user_id:)
|
7
|
-
get("#{PATH}/#{user_id}")
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_pending_users(
|
11
|
-
limit: nil,
|
12
|
-
starting_after_id: nil
|
13
|
-
)
|
14
|
-
query_params = {
|
15
|
-
limit: limit,
|
16
|
-
starting_after_id: starting_after_id,
|
17
|
-
}
|
18
|
-
|
19
|
-
request = request_with_query_params("#{PATH}/pending", query_params)
|
20
|
-
|
21
|
-
get(request)
|
22
|
-
end
|
23
|
-
|
24
|
-
def create_user(
|
25
|
-
email: nil,
|
26
|
-
phone_number: nil,
|
27
|
-
name: {},
|
28
|
-
attributes: {}
|
29
|
-
)
|
30
|
-
request = {
|
31
|
-
email: email,
|
32
|
-
phone_number: phone_number
|
33
|
-
}
|
34
|
-
|
35
|
-
request[:name] = name if name != {}
|
36
|
-
request[:attributes] = attributes if attributes != {}
|
37
|
-
|
38
|
-
post(PATH, request)
|
39
|
-
end
|
40
|
-
|
41
|
-
def update_user(
|
42
|
-
user_id:,
|
43
|
-
name: {},
|
44
|
-
emails: [],
|
45
|
-
phone_numbers: [],
|
46
|
-
attributes: {}
|
47
|
-
)
|
48
|
-
request = {
|
49
|
-
emails: format_emails(emails),
|
50
|
-
phone_numbers: format_phone_numbers(phone_numbers),
|
51
|
-
}
|
52
|
-
|
53
|
-
request[:name] = name if name != {}
|
54
|
-
request[:attributes] = attributes if attributes != {}
|
55
|
-
|
56
|
-
put("#{PATH}/#{user_id}", request)
|
57
|
-
end
|
58
|
-
|
59
|
-
def delete_user(user_id:)
|
60
|
-
delete("#{PATH}/#{user_id}")
|
61
|
-
end
|
62
|
-
|
63
|
-
def delete_user_email(
|
64
|
-
email_id:
|
65
|
-
)
|
66
|
-
delete("#{PATH}/emails/#{email_id}")
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete_user_phone_number(
|
70
|
-
phone_id:
|
71
|
-
)
|
72
|
-
delete("#{PATH}/phone_numbers/#{phone_id}")
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def format_emails(emails)
|
78
|
-
e = []
|
79
|
-
emails.each { |email| e << { email: email} }
|
80
|
-
e
|
81
|
-
end
|
82
|
-
|
83
|
-
def format_phone_numbers(phone_numbers)
|
84
|
-
p = []
|
85
|
-
phone_numbers.each { |phone_number| p << { phone_number: phone_number} }
|
86
|
-
p
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|