2
2
3
3
require 'active_support'
4
4
require 'jwt'
5
- require 'rubygems/deprecate'
6
5
require_relative 'client'
7
6
require_relative '../openapi_client'
8
7
9
8
module Passage
10
9
# The Passage::Auth class provides methods for authenticating requests and tokens
11
10
class Auth
12
- extend Gem ::Deprecate
13
-
14
11
def initialize ( app_id , api_key , auth_strategy )
15
12
@app_cache = ActiveSupport ::Cache ::MemoryStore . new
16
13
@app_id = app_id
@@ -30,37 +27,6 @@ def initialize(app_id, api_key, auth_strategy)
30
27
@magic_links_client = OpenapiClient ::MagicLinksApi . new
31
28
end
32
29
33
- def authenticate_request ( request )
34
- # Get the token based on the strategy
35
- if @auth_strategy == Passage ::COOKIE_STRATEGY
36
- unless request . cookies . key? ( 'psg_auth_token' )
37
- raise PassageError . new (
38
- status_code : 401 ,
39
- body : {
40
- error : 'missing authentication token: expected "psg_auth_token" cookie' ,
41
- code : 'invalid_access_token'
42
- }
43
- )
44
- end
45
- @token = request . cookies [ 'psg_auth_token' ]
46
- else
47
- headers = request . headers
48
- unless headers . key? ( 'Authorization' )
49
- raise PassageError . new (
50
- status_code : 401 ,
51
- body : {
52
- error : 'no authentication token in header' ,
53
- code : 'invalid_access_token'
54
- }
55
- )
56
- end
57
-
58
- @token = headers [ 'Authorization' ] . split ( ' ' ) . last
59
- end
60
-
61
- validate_jwt ( @token )
62
- end
63
-
64
30
def validate_jwt ( token )
65
31
raise ArgumentError , 'jwt is required.' unless token && !token . empty?
66
32
@@ -101,19 +67,6 @@ def validate_jwt(token)
101
67
)
102
68
end
103
69
104
- def revoke_user_refresh_tokens ( user_id )
105
- warn 'NOTE: Passage::Auth#revoke_user_refresh_tokens is deprecated;
106
- use Passage::User#revoke_refresh_tokens instead. It will be removed on or after 2024-12.'
107
- user_exists? ( user_id )
108
-
109
- @tokens_client . revoke_user_refresh_tokens ( @app_id , user_id , @req_opts )
110
- rescue Faraday ::Error => e
111
- raise PassageError . new (
112
- status_code : e . response [ :status ] ,
113
- body : e . response [ :body ]
114
- )
115
- end
116
-
117
70
def create_magic_link_with_email ( email , type , send , opts = { } )
118
71
args = { }
119
72
args [ 'email' ] = email
@@ -144,17 +97,7 @@ def create_magic_link_with_user(user_id, channel, type, send, opts = {})
144
97
create_magic_link ( args , opts )
145
98
end
146
99
147
- def fetch_app
148
- client = OpenapiClient ::AppsApi . new
149
- response = client . get_app ( @app_id )
150
-
151
- response . app
152
- rescue Faraday ::Error => e
153
- raise PassageError . new (
154
- status_code : e . response [ :status ] ,
155
- body : e . response [ :body ]
156
- )
157
- end
100
+ private
158
101
159
102
def fetch_jwks
160
103
app_cache = get_cache ( @app_id )
@@ -180,12 +123,6 @@ def fetch_jwks
180
123
end
181
124
end
182
125
183
- def authenticate_token ( token )
184
- validate_jwt ( token )
185
- end
186
-
187
- private
188
-
189
126
def create_magic_link ( args , opts )
190
127
args [ 'language' ] = opts [ 'language' ]
191
128
args [ 'magic_link_path' ] = opts [ 'magic_link_path' ]
@@ -234,9 +171,5 @@ def get_cache(key)
234
171
def set_cache ( key :, jwks :)
235
172
@app_cache . write ( key , jwks , expires_in : 86_400 )
236
173
end
237
- deprecate ( :authenticate_request , :validate_jwt , 2025 , 1 )
238
- deprecate ( :authenticate_token , :validate_jwt , 2025 , 1 )
239
- deprecate ( :fetch_app , :none , 2025 , 1 )
240
- deprecate ( :fetch_jwks , :none , 2025 , 1 )
241
174
end
242
175
end
0 commit comments