Reputation: 97
Using this tutorial I have been able to set up my Rails API with knock, but authentication doesn't seem to be working when I provide the JWT.
Here is my Knock.rb
Knock.setup do |config|
config.token_audience = -> { Rails.application.secrets.auth0_client_id }
config.token_secret_signature_key = -> { Rails.application.secrets.auth0_client_secret }
end
User.rb:
class User < ApplicationRecord
has_secure_password
def self.from_token_payload payload
payload['sub']
end
end
projects_controller.rb:
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :update, :destroy]
before_action :authenticate_user
# GET /projects
def index
@projects = Project.all
json_response(@projects)
end
...
end
I got the JWT with a POST request to https://my-auth0-site.auth0.com/oauth/token
Upvotes: 3
Views: 386
Reputation: 1
I had the same problem without being able to make it work. At the end I changed to the method recommended by the official Auth0 documentation. It is really simple and works perfect.
https://auth0.com/docs/quickstart/backend/rails/01-authorization
Hope it helps.
Upvotes: 0