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

查看:61
本文介绍了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' 'omniauth-facebook' 'omniauth-twitter'宝石到gemfile

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

有两个问题:

  1. 当我 http://localhost:3000/auth/facebook 时,我得到了 { 错误": { "message":缺少client_id参数.", "type":"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天全站免登陆