stytch 2.1.0 → 2.4.0
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/README.md +48 -10
- data/lib/stytch/client.rb +3 -1
- data/lib/stytch/magic_links.rb +20 -1
- data/lib/stytch/otps.rb +49 -2
- data/lib/stytch/sessions.rb +50 -0
- data/lib/stytch/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6f511de04dc81d999863698f74e78e602ef56b0ad69ebeda06fba44d30066be
|
4
|
+
data.tar.gz: 6c167abff08d5fc5c418499443bf030b95bb5d8a8a2185bb29729372abc42011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2471cf9eba300cbd8110f23a260b7e926f4fc33ed8b19af55e7c8a9f90457ec24823d95b86b3116912473cef5b45219491e445d3e83c6a1b2809fba6e7a53a6f
|
7
|
+
data.tar.gz: 61e5e6e89811f4bb5ba94c1bf2c004ce411c5de6c6f3025761fb99310ded9810d5acbdbad507f8a42ef1baaafdbffdd1d1c433f3423e6e05c63c556ced63c7f2
|
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/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/lib/stytch/client.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
require_relative 'users'
|
4
4
|
require_relative 'magic_links'
|
5
5
|
require_relative 'otps'
|
6
|
+
require_relative 'sessions'
|
6
7
|
|
7
8
|
module Stytch
|
8
9
|
class Client
|
9
10
|
ENVIRONMENTS = %i[live test].freeze
|
10
11
|
|
11
|
-
attr_reader :users, :magic_links, :otps
|
12
|
+
attr_reader :users, :magic_links, :otps, :sessions
|
12
13
|
|
13
14
|
def initialize(env:, project_id:, secret:, &block)
|
14
15
|
@api_host = api_host(env)
|
@@ -20,6 +21,7 @@ module Stytch
|
|
20
21
|
@users = Stytch::Users.new(@connection)
|
21
22
|
@magic_links = Stytch::MagicLinks.new(@connection)
|
22
23
|
@otps = Stytch::OTPs.new(@connection)
|
24
|
+
@sessions = Stytch::Sessions.new(@connection)
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
data/lib/stytch/magic_links.rb
CHANGED
@@ -16,10 +16,27 @@ module Stytch
|
|
16
16
|
@email = Stytch::MagicLinks::Email.new(@connection)
|
17
17
|
end
|
18
18
|
|
19
|
+
def create(
|
20
|
+
user_id:,
|
21
|
+
expiration_minutes: nil,
|
22
|
+
attributes: {}
|
23
|
+
)
|
24
|
+
request = {
|
25
|
+
user_id: user_id
|
26
|
+
}
|
27
|
+
|
28
|
+
request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
|
29
|
+
request[:attributes] = attributes if attributes != {}
|
30
|
+
|
31
|
+
post_request(PATH.to_s, request)
|
32
|
+
end
|
33
|
+
|
19
34
|
def authenticate(
|
20
35
|
token:,
|
21
36
|
attributes: {},
|
22
|
-
options: {}
|
37
|
+
options: {},
|
38
|
+
session_token: nil,
|
39
|
+
session_duration_minutes: nil
|
23
40
|
)
|
24
41
|
request = {
|
25
42
|
token: token
|
@@ -27,6 +44,8 @@ module Stytch
|
|
27
44
|
|
28
45
|
request[:attributes] = attributes if attributes != {}
|
29
46
|
request[:options] = options if options != {}
|
47
|
+
request[:session_token] = session_token unless session_token.nil?
|
48
|
+
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
30
49
|
|
31
50
|
post_request("#{PATH}/authenticate", request)
|
32
51
|
end
|
data/lib/stytch/otps.rb
CHANGED
@@ -6,7 +6,7 @@ module Stytch
|
|
6
6
|
class OTPs
|
7
7
|
include Stytch::RequestHelper
|
8
8
|
|
9
|
-
attr_reader :sms, :whatsapp
|
9
|
+
attr_reader :sms, :whatsapp, :email
|
10
10
|
|
11
11
|
PATH = '/v1/otps'
|
12
12
|
|
@@ -15,13 +15,16 @@ module Stytch
|
|
15
15
|
|
16
16
|
@sms = Stytch::OTPs::SMS.new(@connection)
|
17
17
|
@whatsapp = Stytch::OTPs::WhatsApp.new(@connection)
|
18
|
+
@email = Stytch::OTPs::Email.new(@connection)
|
18
19
|
end
|
19
20
|
|
20
21
|
def authenticate(
|
21
22
|
method_id:,
|
22
23
|
code:,
|
23
24
|
attributes: {},
|
24
|
-
options: {}
|
25
|
+
options: {},
|
26
|
+
session_token: nil,
|
27
|
+
session_duration_minutes: nil
|
25
28
|
)
|
26
29
|
request = {
|
27
30
|
method_id: method_id,
|
@@ -30,6 +33,8 @@ module Stytch
|
|
30
33
|
|
31
34
|
request[:attributes] = attributes if attributes != {}
|
32
35
|
request[:options] = options if options != {}
|
36
|
+
request[:session_token] = session_token unless session_token.nil?
|
37
|
+
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
33
38
|
|
34
39
|
post_request("#{PATH}/authenticate", request)
|
35
40
|
end
|
@@ -117,5 +122,47 @@ module Stytch
|
|
117
122
|
post_request("#{PATH}/login_or_create", request)
|
118
123
|
end
|
119
124
|
end
|
125
|
+
|
126
|
+
class Email
|
127
|
+
include Stytch::RequestHelper
|
128
|
+
|
129
|
+
PATH = "#{Stytch::OTPs::PATH}/email"
|
130
|
+
|
131
|
+
def initialize(connection)
|
132
|
+
@connection = connection
|
133
|
+
end
|
134
|
+
|
135
|
+
def send(
|
136
|
+
email:,
|
137
|
+
expiration_minutes: nil,
|
138
|
+
attributes: {}
|
139
|
+
)
|
140
|
+
request = {
|
141
|
+
email: email,
|
142
|
+
expiration_minutes: expiration_minutes
|
143
|
+
}
|
144
|
+
|
145
|
+
request[:attributes] = attributes if attributes != {}
|
146
|
+
|
147
|
+
post_request("#{PATH}/send", request)
|
148
|
+
end
|
149
|
+
|
150
|
+
def login_or_create(
|
151
|
+
email:,
|
152
|
+
expiration_minutes: nil,
|
153
|
+
attributes: {},
|
154
|
+
create_user_as_pending: false
|
155
|
+
)
|
156
|
+
request = {
|
157
|
+
email: email,
|
158
|
+
expiration_minutes: expiration_minutes,
|
159
|
+
create_user_as_pending: create_user_as_pending
|
160
|
+
}
|
161
|
+
|
162
|
+
request[:attributes] = attributes if attributes != {}
|
163
|
+
|
164
|
+
post_request("#{PATH}/login_or_create", request)
|
165
|
+
end
|
166
|
+
end
|
120
167
|
end
|
121
168
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'request_helper'
|
4
|
+
|
5
|
+
module Stytch
|
6
|
+
class Sessions
|
7
|
+
include Stytch::RequestHelper
|
8
|
+
|
9
|
+
PATH = '/v1/sessions'
|
10
|
+
|
11
|
+
def initialize(connection)
|
12
|
+
@connection = connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(user_id:)
|
16
|
+
query_params = {
|
17
|
+
user_id: user_id
|
18
|
+
}
|
19
|
+
|
20
|
+
request = request_with_query_params(PATH, query_params)
|
21
|
+
|
22
|
+
get_request(request)
|
23
|
+
end
|
24
|
+
|
25
|
+
def authenticate(
|
26
|
+
session_token:,
|
27
|
+
session_duration_minutes: nil
|
28
|
+
)
|
29
|
+
request = {
|
30
|
+
session_token: session_token
|
31
|
+
}
|
32
|
+
|
33
|
+
request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
|
34
|
+
|
35
|
+
post_request("#{PATH}/authenticate", request)
|
36
|
+
end
|
37
|
+
|
38
|
+
def revoke(
|
39
|
+
session_id: nil,
|
40
|
+
session_token: nil
|
41
|
+
)
|
42
|
+
request = {}
|
43
|
+
|
44
|
+
request[:session_id] = session_id unless session_id.nil?
|
45
|
+
request[:session_token] = session_token unless session_token.nil?
|
46
|
+
|
47
|
+
post_request("#{PATH}/revoke", request)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/stytch/version.rb
CHANGED
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: 2.
|
4
|
+
version: 2.4.0
|
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-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -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
|
@@ -73,6 +75,7 @@ files:
|
|
73
75
|
- lib/stytch/middleware.rb
|
74
76
|
- lib/stytch/otps.rb
|
75
77
|
- lib/stytch/request_helper.rb
|
78
|
+
- lib/stytch/sessions.rb
|
76
79
|
- lib/stytch/users.rb
|
77
80
|
- lib/stytch/version.rb
|
78
81
|
- stytch.gemspec
|