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

chore: Use secret_key vs api_key #67

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Then you can instantiate a `Clerk::SDK` instance and access all
Here's a quick example:

```ruby
clerk = Clerk::SDK.new(api_key: "your_api_key")
clerk = Clerk::SDK.new(secret_key: "your_clerk_secret_key")
# List all users
clerk.users.all
# Get your first user
Expand Down Expand Up @@ -87,9 +87,9 @@ supported configuration settings their environment variable equivalents:

```ruby
Clerk.configure do |c|
c.api_key = "your_api_key" # if omitted: ENV["CLERK_SECRET_KEY"] - API calls will fail if unset
c.base_url = "https://..." # if omitted: ENV["CLERK_API_BASE"] - defaults to "https://api.clerk.com/v1/"
c.publishable_key = "pk_(test|live)_...." # if omitted: ENV["CLERK_PUBLISHABLE_KEY"] - Handshake mechanism (check section below) will fail if unset
c.secret_key = "your_clerk_secret_key" # if omitted: ENV["CLERK_SECRET_KEY"] - API calls will fail if unset
c.logger = Logger.new(STDOUT) # if omitted, no logging
c.middleware_cache_store = ActiveSupport::Cache::FileStore.new("/tmp/clerk_middleware_cache") # if omitted: no caching
c.excluded_routes ["/foo", "/bar/*"]
Expand All @@ -101,7 +101,7 @@ arguments to the constructor:

```ruby
clerk = Clerk::SDK.new(
api_key: "X",
secret_key: "X",
base_url: "Y",
logger: Logger.new()
)
Expand Down
6 changes: 3 additions & 3 deletions lib/clerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def configuration

class Config
PRODUCTION_BASE_URL = "https://api.clerk.dev/v1/".freeze
attr_accessor :api_key, :base_url, :publishable_key, :logger, :middleware_cache_store
attr_accessor :base_url, :publishable_key, :secret_key, :logger, :middleware_cache_store

# An array of route paths on which the middleware will not execute.
#
Expand All @@ -44,11 +44,11 @@ class Config

def initialize
@base_url = ENV.fetch("CLERK_API_BASE", PRODUCTION_BASE_URL)
@api_key = ENV["CLERK_API_KEY"]
@secret_key = ENV["CLERK_API_KEY"]

secret_key = ENV["CLERK_SECRET_KEY"]
if secret_key && !secret_key.empty?
@api_key = secret_key
@secret_key = secret_key
end

@publishable_key = ENV["CLERK_PUBLISHABLE_KEY"]
Expand Down
4 changes: 2 additions & 2 deletions lib/clerk/authenticate_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def initialize(request, config)
# The following properties are part of the props supported in all the AuthenticateContext
# objects across all of our SDKs (eg JS, Go)
def secret_key
raise Errors::Configuration, 'Clerk secret key is not set' if @config.api_key.to_s.empty?
raise Errors::Configuration, 'Clerk secret key is not set' if @config.secret_key.to_s.empty?

@config.api_key.to_s
@config.secret_key.to_s
end

def publishable_key
Expand Down
10 changes: 5 additions & 5 deletions lib/clerk/sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.jwks_cache
@@jwks_cache
end

def initialize(api_key: nil, base_url: nil, logger: nil, ssl_verify: true,
def initialize(secret_key: nil, base_url: nil, logger: nil, ssl_verify: true,
connection: nil)
if connection
# Inject a Faraday::Connection for testing or full control over Faraday
Expand All @@ -51,18 +51,18 @@ def initialize(api_key: nil, base_url: nil, logger: nil, ssl_verify: true,
URI(base_url)
end

api_key ||= Clerk.configuration.api_key
secret_key ||= Clerk.configuration.secret_key

if Faraday::VERSION.to_i >= 2 && api_key.nil?
api_key = -> { raise ArgumentError, "Clerk secret key is not set" }
if Faraday::VERSION.to_i >= 2 && secret_key.nil?
secret_key = -> { raise ArgumentError, "Clerk secret key is not set" }
end

logger = logger || Clerk.configuration.logger
@conn = Faraday.new(
url: base_uri, headers: DEFAULT_HEADERS, ssl: {verify: ssl_verify}
) do |f|
f.request :url_encoded
f.request :authorization, "Bearer", api_key
f.request :authorization, "Bearer", secret_key
if logger
f.response :logger, logger do |l|
l.filter(/(Authorization: "Bearer) (\w+)/, '\1 [SECRET]')
Expand Down
2 changes: 1 addition & 1 deletion test/sdk_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_application_json_encoding
assert_equal "user_1", user["id"]
end

def test_no_api_key_raises_on_api_call
def test_no_secret_key_raises_on_api_call
sdk = ::Clerk::SDK.new
assert_raises ArgumentError do
sdk.users.find("x")
Expand Down
Loading