From 095e1c7b7b11d2561fa61db2959da9fc2d554d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Wed, 28 Sep 2022 10:22:11 +0800 Subject: [PATCH] fixed oauth2.0 --- config/initializers/doorkeeper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 512cb36a..dadf43e9 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -11,7 +11,7 @@ Doorkeeper.configure do # raise "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}" # Put your resource owner authentication logic here. # Example implementation: - User.find_by(id: session[:www_user_id]) || redirect_to(new_user_session_url) + User.find_by(login: params[:auth]) || redirect_to("/oauth2?call_url=#{request.fullpath}") end resource_owner_from_credentials do |routes| @@ -243,8 +243,8 @@ Doorkeeper.configure do # For more information go to # https://doorkeeper.gitbook.io/guides/ruby-on-rails/scopes # - # default_scopes :public - # optional_scopes :write, :update + default_scopes :public + optional_scopes :write, :update # Allows to restrict only certain scopes for grant_type. # By default, all the scopes will be available for all the grant types. @@ -514,19 +514,19 @@ Doorkeeper::JWT.configure do # about the user. Defaults to a randomly generated token in a hash: # { token: "RANDOM-TOKEN" } token_payload do |opts| - user = User.find(opts[:resource_owner_id]) + user = User.find_by(id: opts[:resource_owner_id]) { - iss: 'My App', + iss: 'Osredm', iat: Time.current.utc.to_i, # @see JWT reserved claims - https://tools.ietf.org/html/draft-jones-json-web-token-07#page-7 jti: SecureRandom.uuid, user: { - id: user.id, - login: user.login, - mail: user.mail + id: user&.id, + login: user&.login, + mail: user&.mail } } end