问题描述
我正在使用一个名为huggin的开源项目,我想添加一个新的自定义omniauth,以便创建新的代理。我的目标是让tuya直接从huggin进行管理,并通过两个独立的GEMS与其他代理进行事情,其中一个独立的GEMS用于omniauth,另一个独立的用于代理。
因此,我创建了一个新的omniauth策略(从37signals,dropbox,lifx和其他一些网站获得了灵感),但是每次登录时,我都会遇到错误: / p>
在/ auth / tuya / callback上的RuntimeError:找不到有效的映射 路径“ / auth / tuya / callback”
策略如下:
module OmniAuth
module Strategies
class Tuya < OmniAuth::Strategies::OAuth2
option :client_options,{
:site => 'https://openapi.tuyaeu.com',:authorize_url => '/login/open/tuya/login/v1/index.html',}
uid {
user_uuid
}
def user_uuid
all_devices
@user_uuid
end
def all_devices
return @all_devices if @all_devices
@all_devices = {}
uri = URI("https://api.tuya.com/v1/devices/all")
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer #{access_token.token}"
Net::HTTP.start(uri.host,uri.port,:use_ssl => true) do |http|
res = http.request(req)
@user_uuid = res["uid"]
@all_devices = JSON.parse(res.body)
end
return @all_devices
end
end
end
end
gemspec:
# coding: utf-8
lib = File.expand_path('../lib',__FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'omniauth/tuya/version'
Gem::Specification.new do |spec|
spec.name = "omniauth-tuya"
spec.version = Omniauth::Tuya::VERSION
spec.authors = ["Example name"]
spec.email = ["mail@example.com"]
spec.summary = %q{The Tuya startegy for OmniAuth}
spec.description = %q{The Tuya strategy for OmniAuth 1.x}
spec.homepage = "https://example.com"
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency 'omniauth','~> 1.0'
spec.add_dependency 'omniauth-oauth2','~> 1.1'
spec.add_development_dependency "bundler","~> 1.11"
spec.add_development_dependency "rake","~> 10.0"
end
代理通过以下方式将其添加到设计中:
require "huginn_tuya_agents/version"
require "huginn_agent"
require "omniauth-tuya"
require "devise"
module HuginnTuyaAgents
I18n.load_path << "#{File.dirname(__FILE__)}/locales/devise.en.yml"
begin
Devise.setup do |config|
if defined?(OmniAuth::Strategies::Tuya) &&
(key = ENV["TUYA_CLIENT_ID"]).present? &&
(secret = ENV["TUYA_CLIENT_SECRET"]).present?
config.omniauth :tuya,key,secret
end
end
end
end
HuginnAgent.load 'huginn_tuya_agents/clients/tuya_client'
HuginnAgent.load 'huginn_tuya_agents/concerns/tuya_agentable'
HuginnAgent.load 'huginn_tuya_agents/service_option'
HuginnAgent.register 'huginn_tuya_agents/tuya_pulse_lights_agent'
HuginnAgent.register 'huginn_tuya_agents/tuya_toggle_lights_agent'
在终端中运行OmniAuth::Strategies.constants
会给出以下输出:
[:Evernote,:DropboxOauth2,:Twitter,:Tuya,:Developer,:OAuth2,:ThirtySevenSignals,:Wunderlist,:Tumblr,:OAuth]
因此omniauth已注册,但是以某种方式返回到应用程序时仍然出现错误。
有人对如何解决此问题或如何创建此自定义omniauth有想法吗? 请记住,我无法更改核心行为,否则可能会失去与其他huggin代理的兼容性。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)