如何在Laravel 5.1中使用Github,Facebook,Gmail和Twitter登录? [英] How to login using Github, Facebook, Gmail and Twitter in Laravel 5.1?

查看:87
本文介绍了如何在Laravel 5.1中使用Github,Facebook,Gmail和Twitter登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel 5.1中的社交网站登录.我已经安装了socialite,并在以下教程中进行了以下操作:

I am trying to login using social sites in Laravel 5.1. I have installed socialite and following below tutorial:

https://mattstauffer.co/blog /using-github-authentication-for-login-with-laravel-socialite

http://tutsnare.com/social-authentication-in-laravel- 5/

我已经按照每个步骤进行操作,当尝试使用Github登录时,它重定向到Github,登录后重定向到URL回调,但是我的问题是它不会在数据库中存储用户数据.

I have followed every step, when try to login using Github, it redirect to Github and after login it redirect to URL callback, but my problem is it won't store user data in my database.

Update-1

现在,我的问题是如何使用社交网络对用户进行身份验证.以下是我的代码,但抛出错误,提示未定义的索引密码.该错误是因为Auth::attempt()具有密码参数.

Now my problem is how to authenticate user using social network. Following is my code but it throw an error saying undefined index password. That error because Auth::attempt() has passsword parameter.

if (Auth::attempt(['email' => $email, 'user_id' => $user_id])) {
  return redirect()->intended('user/UserDashboard');
} else {
  here i am going to insert if user not logged in already
}

更新2

经过一些研究,我意识到我需要创建自定义身份验证驱动程序.如果有任何想法,请发表您的答案

After some research i realized that i need to create Custom Authentication Drivers. If any one have idea please post your answers

一年前问过的相同问题

使用Google帐户登录Laravel

推荐答案

我认为第一件事就是您已经运行php artisan migrate(而可能是您的主要问题).

Well the very first thing that I assume is that you have ran php artisan migrate(And that may be your main problem).

接下来是在将数据存储到数据库时遇到的问题,您是否从该 Class \App\User到数据库的连接正常?如果您使用其他名称命名,我会要求您在第一个\App\[YourClassName]之后更改该部分.

Next the problem that you have while storing data to database, do you have a working connection to your database from that Class \App\User? If you have named it something different I request you to change that part after the first \App\[YourClassName].

好吧,如果这正常工作,则可能在取回数据时遇到了问题.只需尝试以其他不同的方式执行以下操作即可:

Alright if that's working properly, you might have problem with getting data back. Just try doing somewhat like this in some different route:

<?php
    //Routes.php

    Route::get('trygithub', function(){
        $user = Socialize::with('github')->user()
        dd($user);
    });

如果您在屏幕上得到一些输出,那就可以了.如果您什么都没有得到,请尝试检查您的github配置.

And if you get some output on the screen, well that's OK. If you do not get anything, try to check your github configurations.

是的,还有一件事...仍然,如果您没有得到所需的输出,请尝试在下面进行注释.但是我非常确定这肯定会起作用.

And yeah just one more thing... Still if you do not get desired output, try to comment below. But I am pretty much sure that this ones will definitely work.

更新1个答案:

如果您想尝试为用户登录,并且使用的是诸如FB之类的任何社交资料,则需要这样操作:

If you want to attempt login for your user, and you are using any social profile like let's say FB, you need to go like this:

这不仅是FB的一种情况,还获得了一些特定的代码,例如Google中的代码,您获得了一个刷新令牌代码,而Twitter中则获得了永久访问令牌和机密.因此,只要尝试这样就可以了.或者,使用一个特定的术语作为用户密码. str_random()可能会有所帮助,我强烈建议您不要使用这两个.

And that's not just one case of FB, you get some specific codes like in Google, you get one refresh token code and in twitter a permanent access token and secret. So just try to go like that. Or, have one specific term as a password for your user. str_random() may be helpful in that way and I strongly recommend that instead of these two.

更新2个答案:

我不建议您进行此操作,因为如果您重新发明轮子,您将一无所获.但是,如果您想经历那种令人讨厌的过程,请此处是链接.

I do not recommend going through this because you will not get anything by reinventing the wheel. But still if you want to go through that nasty process, here's the link.

http://laravel.com/docs/5.1/authentication #adding-custom-authentication-drivers

这篇关于如何在Laravel 5.1中使用Github,Facebook,Gmail和Twitter登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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