目前我使用omniauth对用户进行身份验证。这在我的会话控制器中看起来像这样并且运行良好:
def create
auth = request.env['omniauth.auth']
unless @auth = Authentication.find_from_hash(auth)
# Create a new user or add an auth to existing user, depending on
# whether there is already a user signed in.
@auth = Authentication.create_from_hash(auth, current_user)
end
# Log the authorizing user in.
self.current_user = @auth.user
redirect_to authentications_url, :notice => "You've signed in!"
end
在此之后,我将 twitter uid 存储在我的身份验证表中(我也使用linkedin、facebook)并且我认为twitter 会话已关闭。
我现在如何进行身份验证以便可以使用 Twitter gem?我认为如果我在omniauth回调之后立即调用它应该是这样的。
token = auth['credentials']['token'],
secret = auth['credentials']['secret']
Twitter.oauth_token = token
Twitter.oauth_token_secret = secret
我显然需要重新启动会话并将令牌和密码放在正确的位置。我怎样才能创建一个方法来做到这一点?