stytch 2.0.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1f99d2093072e2e5ee91b23fa745105f56a4ae2b8abcd4ce01f76048d9bec42
4
- data.tar.gz: 718a09bc69310b8e30627ebe66cdddb49713f9101dd06cfe13746c8ad88a0ff3
3
+ metadata.gz: 95cdc60c0add8eb1aba7e844f54ed5e9c9ed3dc26ad299870a07d897634801b6
4
+ data.tar.gz: e88adcfd927ea90cfa200909e95706a765cd22c6153105a2206ee6aaa9840102
5
5
  SHA512:
6
- metadata.gz: a90634d8f228fd2860f3674dc7fd522d0d14cf0c36928bc547cafcba1e428597de622e503d1e1758df2fe90e62d0ca6e6fcdb8ff73232b6ce73cdd7b77565591
7
- data.tar.gz: 48117adc597da070fdd886e3bb30e9a27820913933dfe3636b1222a698ad135837debee40c4d71d04d984075a1d324659e25e9e5b7368452add397698027e60a
6
+ metadata.gz: 435c13d8d023dc519b00ca38b1c1a3b149cc01530e71b1dedd30a4f60ca0a63064c5c226f5af48a04aff1cf4d57962783d1fa9f15ca439f6b543960b40de9b51
7
+ data.tar.gz: da191a50f950473cb38337e867f3732a6263e862aa9a22245c003ecbd4586d009e0d3c5b62147e046e521ddff31e28967f533ee0937a6dddcd9b9adf929a4c6e
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 alex@stytch.com. All
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
- Welcome to the official Stytch ruby gem! This gem provides easy access to Stytch's API.
3
+ The Stytch Ruby gem makes it easy to use the Stytch user infrastructure API in Ruby applications.
4
4
 
5
- ## Installation
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
- To make a request, first create a Stytch Client.
24
- Set `env` to either `:test` or `:api` depending on which environment you want to use.
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
- Then make desired API call.
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
- client.users.get(user_id: user_id)
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](https://github.com/stytchauth/stytch-ruby/blob/main/CODE_OF_CONDUCT.md).
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
@@ -19,7 +19,9 @@ module Stytch
19
19
  def authenticate(
20
20
  token:,
21
21
  attributes: {},
22
- options: {}
22
+ options: {},
23
+ session_token: nil,
24
+ session_duration_minutes: nil
23
25
  )
24
26
  request = {
25
27
  token: token
@@ -27,6 +29,8 @@ module Stytch
27
29
 
28
30
  request[:attributes] = attributes if attributes != {}
29
31
  request[:options] = options if options != {}
32
+ request[:session_token] = session_token unless session_token.nil?
33
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
30
34
 
31
35
  post_request("#{PATH}/authenticate", request)
32
36
  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
9
+ attr_reader :sms, :whatsapp, :email
10
10
 
11
11
  PATH = '/v1/otps'
12
12
 
@@ -14,13 +14,17 @@ module Stytch
14
14
  @connection = connection
15
15
 
16
16
  @sms = Stytch::OTPs::SMS.new(@connection)
17
+ @whatsapp = Stytch::OTPs::WhatsApp.new(@connection)
18
+ @email = Stytch::OTPs::Email.new(@connection)
17
19
  end
18
20
 
19
21
  def authenticate(
20
22
  method_id:,
21
23
  code:,
22
24
  attributes: {},
23
- options: {}
25
+ options: {},
26
+ session_token: nil,
27
+ session_duration_minutes: nil
24
28
  )
25
29
  request = {
26
30
  method_id: method_id,
@@ -29,6 +33,8 @@ module Stytch
29
33
 
30
34
  request[:attributes] = attributes if attributes != {}
31
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?
32
38
 
33
39
  post_request("#{PATH}/authenticate", request)
34
40
  end
@@ -74,5 +80,89 @@ module Stytch
74
80
  post_request("#{PATH}/login_or_create", request)
75
81
  end
76
82
  end
83
+
84
+ class WhatsApp
85
+ include Stytch::RequestHelper
86
+
87
+ PATH = "#{Stytch::OTPs::PATH}/whatsapp"
88
+
89
+ def initialize(connection)
90
+ @connection = connection
91
+ end
92
+
93
+ def send(
94
+ phone_number:,
95
+ expiration_minutes: nil,
96
+ attributes: {}
97
+ )
98
+ request = {
99
+ phone_number: phone_number,
100
+ expiration_minutes: expiration_minutes
101
+ }
102
+
103
+ request[:attributes] = attributes if attributes != {}
104
+
105
+ post_request("#{PATH}/send", request)
106
+ end
107
+
108
+ def login_or_create(
109
+ phone_number:,
110
+ expiration_minutes: nil,
111
+ attributes: {},
112
+ create_user_as_pending: false
113
+ )
114
+ request = {
115
+ phone_number: phone_number,
116
+ expiration_minutes: expiration_minutes,
117
+ create_user_as_pending: create_user_as_pending
118
+ }
119
+
120
+ request[:attributes] = attributes if attributes != {}
121
+
122
+ post_request("#{PATH}/login_or_create", request)
123
+ end
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
77
167
  end
78
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stytch
4
- VERSION = '2.0.0'
4
+ VERSION = '2.3.0'
5
5
  end
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.0.0
4
+ version: 2.3.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-06-22 00:00:00.000000000 Z
11
+ date: 2021-09-01 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