Skip to content

Commit ddbac29

Browse files
committed
feat!: remove deprecated Auth methods
1 parent 90c5c3f commit ddbac29

File tree

2 files changed

+2
-158
lines changed

2 files changed

+2
-158
lines changed

lib/passageidentity/auth.rb

+1-68
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
require 'active_support'
44
require 'jwt'
5-
require 'rubygems/deprecate'
65
require_relative 'client'
76
require_relative '../openapi_client'
87

98
module 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
242175
end

tests/auth_test.rb

+1-90
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,13 @@
22

33
require_relative '../lib/passageidentity/client'
44
require 'dotenv'
5-
require 'faraday'
6-
require 'rack'
75
require 'test/unit'
86

97
Dotenv.load('.env')
108

119
# This is a test suite for the Passage Auth API using the Test::Unit framework.
1210
class TestAuthAPI < Test::Unit::TestCase
13-
PassageClient =
14-
Passage::Client.new(app_id: ENV['APP_ID'], api_key: ENV['API_KEY'])
15-
PassageHeaderClient =
16-
Passage::Client.new(
17-
app_id: ENV['APP_ID'],
18-
api_key: ENV['API_KEY'],
19-
auth_strategy: Passage::HEADER_STRATEGY
20-
)
21-
22-
def setup
23-
@test_user =
24-
PassageClient.user.create(
25-
26-
user_metadata: {
27-
example1: 'cool'
28-
}
29-
)
30-
end
11+
PassageClient = Passage::Client.new(app_id: ENV['APP_ID'], api_key: ENV['API_KEY'])
3112

3213
def test_valid_jwt
3314
user_id = PassageClient.auth.validate_jwt(ENV['PSG_JWT'])
@@ -39,74 +20,4 @@ def test_invalid_jwt
3920
PassageClient.auth.validate_jwt('invalid_token')
4021
end
4122
end
42-
43-
def test_valid_authenticate_request_cookie
44-
env = Rack::MockRequest.env_for('https://test.com')
45-
env['HTTP_COOKIE'] = "psg_auth_token=#{ENV['PSG_JWT']}"
46-
cookie_request = Rack::Request.new(env)
47-
user_id = PassageClient.auth.authenticate_request(cookie_request)
48-
assert_equal ENV['TEST_USER_ID'], user_id
49-
end
50-
51-
def test_invalid_authenticate_request_cookie
52-
env_bad_cookie = Rack::MockRequest.env_for('https://test.com')
53-
env_bad_cookie['HTTP_COOKIE'] = 'psg_auth_token=invalid_token}'
54-
bad_cookie_request = Rack::Request.new(env_bad_cookie)
55-
assert_raises Passage::PassageError do
56-
PassageClient.auth.authenticate_request(bad_cookie_request)
57-
end
58-
no_cookie_request = Rack::Request.new({})
59-
assert_raises Passage::PassageError do
60-
PassageClient.auth.authenticate_request(no_cookie_request)
61-
end
62-
end
63-
64-
def test_valid_authenticate_request_header
65-
headers = { 'Authorization' => "Bearer #{ENV['PSG_JWT']}" }
66-
header_request = Faraday.new(url: 'https://test.com', headers: headers)
67-
user_id = PassageHeaderClient.auth.authenticate_request(header_request)
68-
assert_equal ENV['TEST_USER_ID'], user_id
69-
end
70-
71-
def test_invalid_authenticate_request_header
72-
invalid_headers = { 'Authorization' => 'Bearer invalid_token' }
73-
no_header_request = Faraday.new(url: 'https://test.com')
74-
assert_raises Passage::PassageError do
75-
PassageHeaderClient.auth.authenticate_request(no_header_request)
76-
end
77-
Faraday.new(url: 'https://test.com', headers: invalid_headers)
78-
assert_raises Passage::PassageError do
79-
PassageHeaderClient.auth.authenticate_request(no_header_request)
80-
end
81-
end
82-
83-
def test_create_magic_link
84-
magic_link =
85-
PassageClient.create_magic_link(
86-
87-
channel: Passage::EMAIL_CHANNEL,
88-
ttl: 122
89-
)
90-
91-
assert_equal 122, magic_link.ttl
92-
assert_equal '[email protected]', magic_link.identifier
93-
end
94-
95-
def test_invalid_create_magic_link
96-
assert_raises Passage::PassageError do
97-
PassageClient.create_magic_link(
98-
99-
ttl: 122
100-
)
101-
end
102-
end
103-
104-
def test_revoke_user_refresh_tokens
105-
success = PassageClient.auth.revoke_user_refresh_tokens(@test_user.id)
106-
assert_equal nil, success
107-
end
108-
109-
def teardown
110-
PassageClient.user.delete(user_id: @test_user.id)
111-
end
11223
end

0 commit comments

Comments
 (0)