我试图在rails 4中为spotify做OmniAuth。我几乎拥有它,但由于某种原因,重定向URI无法工作。我用的是无所不在的设计,这是我的档案。
User.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:spotify]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
end
end
end
我的回调控制器来处理回调
class CallbacksController < Devise::OmniauthCallbacksController
def spotify
@user = User.from_omniauth(request.env["omniauth.auth"])
sign_in_and_redirect @user
end
end
我的Devise.rb片段:
config.omniauth :spotify, client_id, client_secret,scope: 'playlist-read-private user-read-private user-read-email'
我的Routes.rb
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => 'callbacks' }
get '/users/auth/callback', to: 'callbacks#spotify'
end
最后,指向登录的链接:
<%= link_to 'Sign in with Spotify', user_omniauth_authorize_path(:spotify) %>
但出于某种原因,每当我尝试登录spotify时,它都会说无效的重定向URI
发布于 2015-10-09 07:05:22
好吧,我想出了一个解决我的问题的方法:
这两个文件都在进行API调用,而且都搞砸了。因此,对于任何有这个问题的人,不要同时使用杂耍和设计。老实说,在第一次打嗝之后,我发现设计比建立自己的用户模型和应用无所不在要有用得多。设计更全面!
https://stackoverflow.com/questions/32983926
复制相似问题