Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove deprecated methods #157

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions lib/passageidentity/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,13 @@
module Passage
# The Passage::Auth class provides methods for authenticating requests and tokens
class Auth
def initialize(app_id, api_key, auth_strategy)
@app_cache = ActiveSupport::Cache::MemoryStore.new
def initialize(app_id:, req_opts:)
@app_id = app_id
@api_key = api_key
@auth_strategy = auth_strategy
ctran88 marked this conversation as resolved.
Show resolved Hide resolved
@req_opts = req_opts

@app_cache = ActiveSupport::Cache::MemoryStore.new
fetch_jwks

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']

@tokens_client = OpenapiClient::TokensApi.new
@magic_links_client = OpenapiClient::MagicLinksApi.new
end

Expand Down
43 changes: 16 additions & 27 deletions lib/passageidentity/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,35 @@

require_relative 'auth'
require_relative 'user_api'
require_relative 'error'
require_relative 'version'

module Passage
COOKIE_STRATEGY = 0
HEADER_STRATEGY = 1

EMAIL_CHANNEL = 'email'
PHONE_CHANNEL = 'phone'

# The Passage::Client class provides methods for interacting with Passage
class Client
attr_reader :auth, :user

def initialize(app_id:, api_key: '', auth_strategy: COOKIE_STRATEGY)
@app_id = app_id
@api_key = api_key

# check for valid auth strategy
unless [COOKIE_STRATEGY, HEADER_STRATEGY].include? auth_strategy
raise PassageError.new(
status_code: 400,
body: {
error: 'Invalid auth strategy',
code: 'invalid_argument'
}
)
def initialize(app_id:, api_key:)
unless app_id && !app_id.empty?
raise ArgumentError,
'A Passage App ID is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
end
unless api_key && !api_key.empty?
raise ArgumentError,
'A Passage API key is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
end

@auth_strategy = auth_strategy

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']
req_opts = {}
req_opts[:header_params] = {
'Passage-Version' => "passage-ruby #{Passage::VERSION}",
'Authorization' => "Bearer #{api_key}"
}
req_opts[:debug_auth_names] = ['header']

@auth = Passage::Auth.new(@app_id, @api_key, @auth_strategy)
@user = Passage::UserAPI.new(@app_id, @api_key)
@auth = Passage::Auth.new(app_id: app_id, req_opts: req_opts)
@user = Passage::UserAPI.new(app_id: app_id, req_opts: req_opts)
end
end
end
16 changes: 5 additions & 11 deletions lib/passageidentity/user_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ module Passage
# The UserAPI class provides methods for interacting with Passage Users
class UserAPI
# rubocop:disable Metrics/AbcSize
def initialize(app_id, api_key)
def initialize(app_id:, req_opts:)
@app_id = app_id
@api_key = api_key
@req_opts = req_opts

@user_client = OpenapiClient::UsersApi.new
@user_device_client = OpenapiClient::UserDevicesApi.new

header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''

@req_opts = {}
@req_opts[:header_params] = header_params
@req_opts[:debug_auth_names] = ['header']
@tokens_client = OpenapiClient::TokensApi.new
end

def get(user_id:)
Expand Down Expand Up @@ -160,8 +155,7 @@ def revoke_refresh_tokens(user_id:)
raise ArgumentError, 'user_id is required.' unless user_id && !user_id.empty?

begin
tokens_client = OpenapiClient::TokensApi.new
tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
@tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
rescue Faraday::Error => e
raise PassageError.new(
status_code: e.response[:status],
Expand Down
Loading