我写了一个oauth提供程序,用于处理我公司的几个Web应用程序.我正在使用门卫宝石,到目前为止效果很好.
典型的行为是用户去客户端应用程序,重定向到供应商登录,确认客户端应用程序被授权访问该用户的信息,并得到重定向回客户端应用程序.但是,我想跳过用户确认客户端应用程序的步骤.我想为他们做,所以没有提示.
我试图模仿我在这里找到的代码,例如:
Doorkeeper::Application.all.each do |application|
auth_params = {response_type: 'code', client_id: application.uid, redirect_uri: application.redirect_uri}
client = Doorkeeper::OAuth::Client.find(application.uid)
authorization = Doorkeeper::OAuth::AuthorizationRequest.new(client, user, auth_params)
authorization.authorize
end
Run Code Online (Sandbox Code Playgroud)
但这不起作用,它仍然为用户提供客户端应用程序的授权/拒绝提示.建议?
我正在为一个需要有条件地设置cookie的rails应用程序编写机架中间件组件.我目前正在试图设置cookie.从谷歌搜索它似乎应该工作:
class RackApp
def initialize(app)
@app = app
end
def call(env)
@status, @headers, @response = @app.call(env)
@response.set_cookie("foo", {:value => "bar", :path => "/", :expires => Time.now+24*60*60})
[@status, @headers, @response]
end
end
Run Code Online (Sandbox Code Playgroud)
它不会产生错误,但也不会设置cookie.我究竟做错了什么?
(注意:我正在使用'therubyracer','react-rails'和'sprockets-coffee-react'宝石)
这是我的简单组件(Hello.js.cjsx)的代码:
# @cjsx React.DOM
Hello = React.createClass(
render: ->
<div>
Hello {@props.name || "World"}!
</div>
)
window.components ?= {}
window.components.Hello = Hello
Run Code Online (Sandbox Code Playgroud)
在我的rails视图(index.html.erb)中,这很好用:
<%= render_component('components.Hello', {name: 'Jack'}) %>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这个:
<%= react_component('components.Hello', {name: 'Jill'}, {prerender: true}) %>
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Encountered error "ReferenceError: components is not defined"
这看起来很奇怪,因为我在我的组件中定义它.
我究竟做错了什么?
我正在查看一些代码并遇到了"require'etc'"行.当然,谷歌搜索"红宝石等宝石"之类的东西已经毫无结果.我还没有找到任何文件(还),所以我想我会问这里.
我正在尝试使用 Ruby 为我的团队编写一个简单的 Slack 聊天机器人。这有点粗糙,因为 Slack 没有对 Ruby 的官方支持。尽管如此,我已经能够使用我编写的代码打开 websocket 并监听 Slack 事件:
# frozen_string_literal: true
require "async"
require "async/io/stream"
require "async/http/endpoint"
require "async/websocket/client"
require "excon"
require "json"
module Slack
class Client
Error = Class.new(StandardError)
AquisitionError = Class.new(Error)
ConnectionError = Class.new(Error)
CONNECTION_AQUISITION_ENDPOINT = "https://slack.com/api/apps.connections.open"
def initialize
@token = "my-app-token"
end
def connect
connection_info = Excon.post(CONNECTION_AQUISITION_ENDPOINT, headers: {
"Content-type": "application/x-www-form-urlencoded",
Authorization: "Bearer #{@token}",
})
result = JSON.parse(connection_info.body)
raise(AquisitionError) unless result["ok"] # better error later
websocket = Async::HTTP::Endpoint.parse(result["url"])
Async do |_task|
Async::WebSocket::Client.connect(websocket) …
Run Code Online (Sandbox Code Playgroud)