stytch 2.1.1 → 2.5.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: f10d2ac983b6812590a7d1d01fa649ea9a84bcdbff28cdc34b47dc6e075ebcaf
4
- data.tar.gz: '08dbadda02435370eceb0d66533a11631c05ab615e646a0d6fa77d58fb579bdb'
3
+ metadata.gz: 96a3001aced4c8717890e94108fa8ab11c8272f3dff64a271ec16e04fa86853d
4
+ data.tar.gz: ac4224acb1e5242c783728bdfa6ce87e5349a6488d6aee789017870e0caa9749
5
5
  SHA512:
6
- metadata.gz: 5d084490ad18ef02b1f9215356be00e987379b773652a42c22e95058ff38631e8d0d020a93361f1b70c56041451d25e71daf3e6b896e27022185d46045b4fdd0
7
- data.tar.gz: e62da9085f0263fe06c5134747f2b5a5992d6163333a90197e1ab0e1aa2379e7a8d73124fe2d93c443ca1431d36447b64735e2086edc1e73eebfd359b33e8d25
6
+ metadata.gz: fd8d2138c34c2e4d595d6c92d6c51a0df43bd8f0709b55f5fb1536274a0b6827d2ba93e5a46d2dd843352460cd6bc4e8f321255efc8ffd649867056981f4158f
7
+ data.tar.gz: a86d8be0624be63f7be3748641962e10019a729f311c7d5579e577184e099b03bd3cdae5dea761c61bac5d6c3033a6453c9e09dccddba3cd1d3411c965c42ab5
data/lib/stytch/client.rb CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  require_relative 'users'
4
4
  require_relative 'magic_links'
5
+ require_relative 'oauth'
5
6
  require_relative 'otps'
7
+ require_relative 'sessions'
6
8
 
7
9
  module Stytch
8
10
  class Client
9
11
  ENVIRONMENTS = %i[live test].freeze
10
12
 
11
- attr_reader :users, :magic_links, :otps
13
+ attr_reader :users, :magic_links, :oauth, :otps, :sessions
12
14
 
13
15
  def initialize(env:, project_id:, secret:, &block)
14
16
  @api_host = api_host(env)
@@ -19,7 +21,9 @@ module Stytch
19
21
 
20
22
  @users = Stytch::Users.new(@connection)
21
23
  @magic_links = Stytch::MagicLinks.new(@connection)
24
+ @oauth = Stytch::OAuth.new(@connection)
22
25
  @otps = Stytch::OTPs.new(@connection)
26
+ @sessions = Stytch::Sessions.new(@connection)
23
27
  end
24
28
 
25
29
  private
@@ -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
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module Stytch
6
+ class OAuth
7
+ include Stytch::RequestHelper
8
+
9
+ PATH = '/v1/oauth'
10
+
11
+ def initialize(connection)
12
+ @connection = connection
13
+ end
14
+
15
+ def authenticate(
16
+ token:,
17
+ session_management_type: nil
18
+ )
19
+ request = {
20
+ token: token
21
+ }
22
+ request[:session_management_type] = session_management_type unless session_management_type.nil?
23
+
24
+ post_request("#{PATH}/authenticate", request)
25
+ end
26
+ end
27
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stytch
4
- VERSION = '2.1.1'
4
+ VERSION = '2.5.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.1.1
4
+ version: 2.5.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-07-13 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -73,8 +73,10 @@ files:
73
73
  - lib/stytch/client.rb
74
74
  - lib/stytch/magic_links.rb
75
75
  - lib/stytch/middleware.rb
76
+ - lib/stytch/oauth.rb
76
77
  - lib/stytch/otps.rb
77
78
  - lib/stytch/request_helper.rb
79
+ - lib/stytch/sessions.rb
78
80
  - lib/stytch/users.rb
79
81
  - lib/stytch/version.rb
80
82
  - stytch.gemspec