使用 this教程 我已经能够通过敲击设置我的 Rails API,但是当我提供 JWT 时,身份验证似乎不起作用。
这是我的 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
用户.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
我通过对 https://my-auth0-site.auth0.com/oauth/token 的 POST 请求获得了 JWT
最佳答案
关于ruby-on-rails - 使用 Knock 的 Rails API 的 Auth0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46967546/