- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Rails 和 webdev 的新手。尝试使用 Rails + Devise + Doorkeeper(如在 https://github.com/doorkeeper-gem/doorkeeper-provider-app 中)为移动应用程序实现简单的 API。
遇到用户已经收到token无法发起授权请求(POST/oauth/token)的问题。 IE。:
curl -F grant_type=password -F username=1@tothetrip.com -F password=12345678 -X POST http://api.to_the_trip.dev/oauth/token
{"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoyLCJlbWFpbCI6IjFAdG90aGV0cmlwLmNvbSJ9fQ.dYai6nH_KYb9YbDltqwFuzCO3i0igR_gw2T7u_TeVcI","token_type":"bearer","expires_in":7200,"created_at":1435864812}
ActiveRecord::RecordInvalid in Doorkeeper::TokensController#create
Validation failed: Token has already been taken
activerecord (4.2.3) lib/active_record/validations.rb:79:in `raise_record_invalid'
activerecord (4.2.3) lib/active_record/validations.rb:43:in `save!'
activerecord (4.2.3) lib/active_record/attribute_methods/dirty.rb:29:in `save!'
activerecord (4.2.3) lib/active_record/transactions.rb:291:in `block in save!'
activerecord (4.2.3) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
activerecord (4.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.3) lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
activerecord (4.2.3) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.3) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.3) lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
activerecord (4.2.3) lib/active_record/transactions.rb:291:in `save!'
activerecord (4.2.3) lib/active_record/persistence.rb:51:in `create!'
doorkeeper (2.2.1) lib/doorkeeper/models/access_token_mixin.rb:76:in `find_or_create_for'
doorkeeper (2.2.1) lib/doorkeeper/oauth/request_concern.rb:33:in `find_or_create_access_token'
doorkeeper (2.2.1) lib/doorkeeper/oauth/password_access_token_request.rb:30:in `before_successful_response'
doorkeeper (2.2.1) lib/doorkeeper/oauth/request_concern.rb:7:in `authorize'
doorkeeper (2.2.1) lib/doorkeeper/request/password.rb:19:in `authorize'
doorkeeper (2.2.1) app/controllers/doorkeeper/tokens_controller.rb:42:in `authorize_response'
doorkeeper (2.2.1) app/controllers/doorkeeper/tokens_controller.rb:4:in `create'
def find_or_create_for(application, resource_owner_id, scopes, expires_in, use_refresh_token)
if Doorkeeper.configuration.reuse_access_token
access_token = matching_token_for(application, resource_owner_id, scopes)
if access_token && !access_token.expired?
return access_token
end
end
create!(
application_id: application.try(:id),
resource_owner_id: resource_owner_id,
scopes: scopes.to_s,
expires_in: expires_in,
use_refresh_token: use_refresh_token
)
end
Doorkeeper.configure do
# Change the ORM that doorkeeper will use.
# Currently supported options are :active_record, :mongoid2, :mongoid3,
# :mongoid4, :mongo_mapper
orm :active_record
resource_owner_authenticator do
current_user || env['warden'].authenticate!(:scope => :user)
end
resource_owner_from_credentials do |routes|
request.params[:user] = {:email => request.params[:username], :password => request.params[:password]}
request.env["devise.allow_params_authentication"] = true
user = request.env['warden'].authenticate!(:scope => :user)
env['warden'].logout
user
end
access_token_generator "Doorkeeper::JWT"
end
Doorkeeper.configuration.token_grant_types << "password"
Doorkeeper::JWT.configure do
#JWT config
end
require 'api_constraints'
Rails.application.routes.draw do
use_doorkeeper
devise_for :users
namespace :api, defaults: {format: :json}, constraints: { subdomain: 'api' }, path: '/' do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :users, :only => [:show, :create, :update]
get '/me' => "credentials#me"
end
end
end
最佳答案
好吧,如果你想找到答案,那么就提出一个问题。
问题在于 Doorkeeper::JWT token 的默认实现。它在有效载荷中没有任何随机性,因此对于每个用户的身份验证总是相同的。所以我补充说:
Doorkeeper::JWT.configure do
token_payload do |opts|
user = User.find(opts[:resource_owner_id])
{
iss: "myapp", #this
iat: DateTime.current.utc.to_i, #this
rnd: SecureRandom.hex, #and this
user: {
id: user.id,
email: user.email
}
}
end
secret_key "key"
encryption_method :hs256
end
关于ruby-on-rails - 重复授权给 Doorkeeper 错误 422(资源所有者凭据流),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193369/
假设我有一个简单的模型: class Contact(models.Model): owner = models.ForeignKey(User, editable=False) fi
我在docker容器中的轨道上运行ruby。如果生成类似docker-compose run rails rails g controller posts index show的文件,则文件所有者为r
这个问题在这里已经有了答案: Get Component's Parent Form (10 个答案) 关闭 3 年前。 如何从嵌入到表单中的自定义 Winforms 组件获取父/所有者控件? 我有
我这里有密码 @interface FFRightSidebarController () @property (nonatomic, strong) FFActivitiesController *
假设您有这些表:RestaurantChains、Restaurants、MenuItems - 它们之间存在明显的关系。现在,您有表 Comments 和 Ratings,它们存储客户对链式店、餐馆
我有以下 View 层次结构, ... ... .... 单个订单的更新通过推送器进行。 我是 React 新手,想知道以下哪一个是更
所以我有一个位于另一个用户控件内部的用户控件。我们称它们为 ParentUC 和 ChildUC。我需要从 ChildUC 获取 ParentUC。 我知道获取窗口所有者的方法是Window.GetW
我们创建了 Telegram Bot ,它有许多困难的操作。机器人是由一位开发人员使用他的电话号码创建的。是否可以更改机器人的所有者或添加其他用户作为机器人的管理员? 最佳答案 最近出现了将机器人转给
默认情况下,对象(表、存储过程等)是使用 dbo 所有者/架构设置的(我认为 ms sql 2000 称其为所有者,而 ms sql 2005 称其为架构) 所有者/架构实际上是数据库中的角色或用户。
在 Mortar 中,如果 ActionBar 根据显示的屏幕发生变化,我很好奇人们如何处理它。例如,假设您想要在显示特定屏幕时更改 ActionBar 标题或操作。 注入(inject) Activ
我正在使用 Stripe.js 和 Stripe Elements 开发购物车结帐页面,而不是使用 Stripe 的结帐小部件。 在结帐页面上,使用了所有 4 个可用元素(卡片、邮政编码、expire
我尝试将本地仓库推送到 github 并收到这样的消息: The remote end hung up unexpectedly. ERROR: Permission to [repo_name] d
我是 WHM、cPanel 和 CentOS 的新手。 我安装 WHM 然后为域创建一个帐户 app.example.com和用户 peter我将域名指向正确的 IP 地址,但是当我运行我的网站 ap
我已经在 GitHub 上提交了一个项目的问题,该项目不是我的,我也不是贡献者,但我找不到标记我的问题的方法。有没有办法让我给它贴上标签,或者这只适用于贡献者? 最佳答案 它仅适用于贡献者。 这样,您
我到处都找过了,但一直找不到我要找的东西。我知道我需要什么,但无法将 2 和 2 放在一起。 我需要允许用户创建群组并允许其他用户加入群组。 任何用户都可以创建群组。 任何用户都可以发送加入另一个群组
我到处都找过了,但一直找不到我要找的东西。我知道我需要什么,但无法将 2 和 2 放在一起。 我需要允许用户创建群组并允许其他用户加入群组。 任何用户都可以创建群组。 任何用户都可以发送加入另一个群组
这是我的代码: class SpecialMeanings{ String prop1 = "prop1" def closure = { String prop1 = "inner_
我一直在使用 java OWNER 进行基于属性的配置。 我创建了一个静态方法 public static final ApplicationConfiguration config = Config
我正在运行 OpenSSH sftp-server(Linux、Raspbian),FileZilla 用作客户端。我遇到的问题是用户可以删除服务器上的任何文件,而不管文件掩码或所有者/组: 登录的用
这是一个简单的问题,我无法通过谷歌搜索和查看 github documents 找到答案。 . 如果有人对 github 中已关闭的问题发表新评论,是否会通知 Repo 所有者? 最佳答案 如果向已关
我是一名优秀的程序员,十分优秀!