omn​​iauth OAuthException &OAuth::未经授权 [英] omniauth OAuthException & OAuth::Unauthorized

查看:16
本文介绍了omn​​iauth OAuthException &OAuth::未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 omniauth 1.0.另外我有 oauth-0.4.5、oauth2-0.5.1、 omniauth-facebook-1.0.0、 omniauth-twitter-0.0.6.

I have installed omniauth 1.0. Also I have oauth-0.4.5, oauth2-0.5.1, omniauth-facebook-1.0.0, omniauth-twitter-0.0.6.

omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer unless Rails.env.production?
  provider :facebook, ENV['167257285348131'],     ENV['c8c722f697scb2afcf1600286c6212a9'],     :scope => 'email,offline_access,read_stream', :display => 'popup'
  provider :twitter, ENV['fma2L22ObJCW52QrL7uew'], ENV['4aZfhCAOdiS7ap8pHJ7I1OZslFwVWWLiAMVpYUI']

end

session_controller.rb
class SessionsController < ApplicationController
require 'omniauth-facebook'
require 'omniauth-twitter'
require 'omniauth'

def create
    @user = User.find_or_create_from_auth_hash(auth_hash)
    self.current_user = @user
    redirect_to '/'
end



def auth_hash
request.env['omniauth.auth']
end

end

我还补充'全方位''omniauth-facebook''omniauth-twitter' gems 到 gemfile

Also I add 'omniauth' 'omniauth-facebook' 'omniauth-twitter' gems to gemfile

有两个问题:

  1. 当我去 http://localhost:3000/auth/facebook 我得到{错误": {"message": "缺少 client_id 参数.",类型":OAuthException"}}
  1. When I go http://localhost:3000/auth/facebook I get { "error": { "message": "Missing client_id parameter.", "type": "OAuthException" } }

和链接 graph.facebook.com/oauth/authorize?response_type=code&client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&parse=query&scope=email%2Coffline_access%2Cread_stream&display=popup而且没有client_id!!!

And the link graph.facebook.com/oauth/authorize?response_type=code&client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&parse=query&scope=email%2Coffline_access%2Cread_stream&display=popup And there is no client_id!!!

  1. 当我访问 http://localhost:3000/auth/twitter 时,我得到了 OAuth::未经授权
  1. When I go to http://localhost:3000/auth/twitter I get OAuth::Unauthorized

401 未经授权

有什么想法吗?

推荐答案

Alex D. 是正确的,因为 ENV[] 打破了它.要创建 omniauth.rb 以便它在不同的环境中使用不同的键,只需输入:

Alex D. is correct in that the ENV[] breaks it. To create omniauth.rb so that it uses different keys in different environments just put:

provider :twitter, TWITTER_KEY, TWITTER_SECRET

在 omniauth.rb 中

in omniauth.rb

然后在您的环境配置文件(config/environments/development.rb 等)中放入您要用于该环境的密钥.

and then in your environment config files (config/environments/development.rb, etc.) put the key you want to use for that environment.

config/environments/development.rb:

config/environments/development.rb:

TWITTER_KEY = 'aaaaaaa'
TWITTER_SECRET = 'aaaabbbbbb'

config/environments/production.rb:

config/environments/production.rb:

TWITTER_KEY = 'ccccccc'
TWITTER_SECRET = 'ccccdddddd'

这篇关于omn​​iauth OAuthException &amp;OAuth::未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆