- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试设置 Doorkeeper对于我的 API(使用密码授予流程),但每当我尝试检索访问 token 时,我的 Rails 服务器上都会出现以下错误:
ActiveRecord::NotNullViolation (PG::NotNullViolation: ERROR: null value in column "application_id" violates not-null constraint
DETAIL: Failing row contains (1, 1, null, e24EH4dNKBNoHh7OSzzyT_7Cg4Ka52e9TB4TP-vz4aM, null, 7200, null, 2019-07-19 22:50:44.797045, , ).
: INSERT INTO "oauth_access_tokens" ("resource_owner_id", "token", "expires_in", "created_at", "scopes") VALUES ($1, $2, $3, $4, $5) RETURNING "id"):
我关注了门卫的rails getting started guide除了将关联添加到我的用户模型的最后一步——我在遇到错误后尝试这样做,但没有帮助。我目前没有使用 Devise .
我是不是配置不正确?或者也许我必须使用 Devise?我不确定 application_id
字段在哪里发挥作用,因为 doorkeeper 的文档留下了应用程序页面 blank .
我发送给 API 的内容:
grant_type: password
username: test@user.com
password: password
我的 doorkeeper.rb 初始化文件:
Doorkeeper.configure do
# Change the ORM that doorkeeper will use (needs plugins)
orm :active_record
# This block will be called to check whether the resource owner is authenticated or not.
resource_owner_authenticator { current_user || render(status: 401) }
resource_owner_from_credentials do |_routes|
user = User.find_by_email(params[:username].try(:downcase))
user if user && user.authenticate(params[:password])
end
grant_flows %w[password]
end
我的看门人迁移文件:
class CreateDoorkeeperTables < ActiveRecord::Migration[5.2]
def change
create_table :oauth_applications do |t|
t.string :name, null: false
t.string :uid, null: false
t.string :secret, null: false
# Remove `null: false` if you are planning to use grant flows
# that doesn't require redirect URI to be used during authorization
# like Client Credentials flow or Resource Owner Password.
t.text :redirect_uri, null: false
t.string :scopes, null: false, default: ''
t.boolean :confidential, null: false, default: true
t.timestamps null: false
end
add_index :oauth_applications, :uid, unique: true
create_table :oauth_access_grants do |t|
t.references :resource_owner, null: false
t.references :application, null: false
t.string :token, null: false
t.integer :expires_in, null: false
t.text :redirect_uri, null: false
t.datetime :created_at, null: false
t.datetime :revoked_at
t.string :scopes
end
add_index :oauth_access_grants, :token, unique: true
add_foreign_key(
:oauth_access_grants,
:oauth_applications,
column: :application_id
)
create_table :oauth_access_tokens do |t|
t.references :resource_owner, index: true
t.references :application, null: false
# If you use a custom token generator you may need to change this column
# from string to text, so that it accepts tokens larger than 255
# characters. More info on custom token generators in:
# https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
#
# t.text :token, null: false
t.string :token, null: false
t.string :refresh_token
t.integer :expires_in
t.datetime :revoked_at
t.datetime :created_at, null: false
t.string :scopes
# If there is a previous_refresh_token column,
# refresh tokens will be revoked after a related access token is used.
# If there is no previous_refresh_token column,
# previous tokens are revoked as soon as a new access token is created.
# Comment out this line if you'd rather have refresh tokens
# instantly revoked.
t.string :previous_refresh_token, null: false, default: ""
end
add_index :oauth_access_tokens, :token, unique: true
add_index :oauth_access_tokens, :refresh_token, unique: true
add_foreign_key(
:oauth_access_tokens,
:oauth_applications,
column: :application_id
)
# Uncomment below to ensure a valid reference to the resource owner's table
# add_foreign_key :oauth_access_grants, <model>, column: :resource_owner_id
add_foreign_key :oauth_access_tokens, <model>, column: :resource_owner_id
end
end
我的用户模型:
class User < ApplicationRecord
before_save { email.downcase! }
validates :name, presence: true, length: { maximum: 50 }
# VALID_EMAIL_REGEX = (removed for this post)
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
has_secure_password
validates :password, presence: true, length: { minimum: 6 }
end
最佳答案
创建门卫应用。
API 模式:您可以从 Rails 控制台创建应用程序:
application = Doorkeeper::Application.create(
名称:“应用程序名称”,
范围:“读写”,
secret :假的,
redirect_uri: "urn:ietf:wg:oauth:2.0:oob"
)
现在您可以使用application
的uid
(client_id
) 和secret 来请求访问 token 。 密码流
的curl
请求示例:
`curl --location --request POST 'http://localhost:3000/oauth/token?client_id=CLIENT_ID&client_secret=SECRET' --header 'Content-Type: application/json' --header 'Accept: application/json' --data-raw '{"username": "example@email.com", "password": "password", "grant_type": "password" }'`
其他流程(如 Authorization
流程)要求您获得一个 authorization
token ,您可以使用它来请求 access token
.相关wiki:https://github.com/doorkeeper-gem/doorkeeper/wiki/Authorization-Code-Flow
关于ruby-on-rails - "application_id"上的门卫 ActiveRecord::NotNullViolation(密码授予),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57120487/
我正在压倒门卫 AuthorizationsController .作为docs建议我从 AuthorizationsController 继承.现在下面的代码显示了我最新的覆盖尝试。 我目前拥有的
目标 :当 nginx 入口具有事件重写目标功能时,Keycloak 网守部署。 Ingress 根据以下内容重写目标: rewrite.bar.com/something/重写为 rewrite.b
我正在使用带有 Doorkeeper gem 的 Rails 3.2 为第 3 方提供 OAuth 2 API。从应用程序外部使用我的 REST API 时,我不断收到此警告: 警告:无法验证 CSR
我希望我的门卫 View 使用应用程序布局: https://github.com/applicake/doorkeeper/wiki/Customizing-views 这包含主应用程序的路由和辅助
在提供授权的Rails(5.2.3)应用程序上将doorkeeper从5.1.0 gem升级到5.2.1后,请求授权的应用程序的登录不再起作用。授权应用程序上的页面指出缺少必需参数:范围。尽管我们不使
我是一名优秀的程序员,十分优秀!