22
33require 'active_support'
44require 'jwt'
5- require 'rubygems/deprecate'
65require_relative 'client'
76require_relative '../openapi_client'
87
98module Passage
109 # The Passage::Auth class provides methods for authenticating requests and tokens
1110 class Auth
12- extend Gem ::Deprecate
13-
1411 def initialize ( app_id , api_key , auth_strategy )
1512 @app_cache = ActiveSupport ::Cache ::MemoryStore . new
1613 @app_id = app_id
@@ -30,37 +27,6 @@ def initialize(app_id, api_key, auth_strategy)
3027 @magic_links_client = OpenapiClient ::MagicLinksApi . new
3128 end
3229
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-
6430 def validate_jwt ( token )
6531 raise ArgumentError , 'jwt is required.' unless token && !token . empty?
6632
@@ -101,19 +67,6 @@ def validate_jwt(token)
10167 )
10268 end
10369
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-
11770 def create_magic_link_with_email ( email , type , send , opts = { } )
11871 args = { }
11972 args [ 'email' ] = email
@@ -144,17 +97,7 @@ def create_magic_link_with_user(user_id, channel, type, send, opts = {})
14497 create_magic_link ( args , opts )
14598 end
14699
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
158101
159102 def fetch_jwks
160103 app_cache = get_cache ( @app_id )
@@ -180,12 +123,6 @@ def fetch_jwks
180123 end
181124 end
182125
183- def authenticate_token ( token )
184- validate_jwt ( token )
185- end
186-
187- private
188-
189126 def create_magic_link ( args , opts )
190127 args [ 'language' ] = opts [ 'language' ]
191128 args [ 'magic_link_path' ] = opts [ 'magic_link_path' ]
@@ -234,9 +171,5 @@ def get_cache(key)
234171 def set_cache ( key :, jwks :)
235172 @app_cache . write ( key , jwks , expires_in : 86_400 )
236173 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 )
241174 end
242175end
0 commit comments