Repository navigation
Replies: 1 comment 1 reply
|
You probably want require 'roda'
require 'sequel'
DB = Sequel.sqlite
DB.extension :date_arithmetic
DB.create_table(:accounts) do
primary_key :id, :type=>:Bignum
String :email, :null=>false, :unique=>true
String :ph
end
DB.create_table(:account_jwt_refresh_keys) do
primary_key :id, :type=>:Bignum
foreign_key :account_id, :accounts, :null=>false, :type=>:Bignum
String :key, :null=>false
DateTime :deadline, :null=>false, :default=>Sequel.date_add(Sequel::CURRENT_TIMESTAMP, :days=>1)
index :account_id, :name=>:account_jwt_rk_account_id_idx
end
class Roda
plugin :rodauth, json: true do
enable :create_account,
:jwt_refresh,
:login,
:logout
jwt_secret '1'
require_login_confirmation? false
require_password_confirmation? false
account_password_hash_column :ph
end
route do |request|
request.rodauth
end
end
run Roda.freeze.appcurl output: The In the future, consider providing a minimal self contained reproducible example similar to the above, as it makes diagnosis of the problem much faster. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello. 👋
I'm trying to enable web and API authorization at the same time and am getting confused or maybe what I'm trying to do is not supported? Here's a highly truncated middleware class that I'm using:
With the above, I'm only wanting to demonstrate that I have account creation with login and logout support. I also have JWT support too. With the above, this works great for logging in via the web UI but when making an API request it fails. For example, the following will not work:
If I add
json: :onlyto the plugin block, like this:...then the above API request works, and I get the following response:
{ "access_token": "<redacted>", "refresh_token": "1_6_qWf4KQPHhye-a1jCQjE2pbCe-gndCKWbvCh1pJwrBBU", "success": "You have been logged in" }Is there a way in which I can configure Rodauth to gracefully handle both Web and JSON data API (JWT) requests? If not, I assume I need to have different middleware configured for each type of request?
What is the recommended way to handle this?
All reactions