Laravel Auth external data for login and register

只谈情不闲聊 提交于 2019-12-08 01:06:45

问题


I am using the Laravel 5.2 Auth system coming up with this command :

php artisan make:auth

Although this works totally fine as is, my goal is to use an external API to perform login, registering and changing password while still being able to use the core function of the Auth class.

So taking the login for example, I want to use something like

function login(ApiController $api) {
     // This function return data or error code and message in JSON
     $login = $api->login([ $credentials['email'], $credentials['password']]);
     if($login->success) 
       // login successfully like normal Auth would do
     else 
       // redirect to main page with $login->message
}

By the way, I want to pass fields coming up from $login to the Auth class, like we can actually do Auth::user()->email giving us the email, I'd want to set value like "database field" but with my API JSON fields behind

I looked on the Internet and found something to do inside AuthController and something related to ServiceProvider, but I don't know how to follow my exact needs


回答1:


Adding a custom user provider would help in this case. There is no need to play with AuthController here. Check this Laravel Docs page.

You will need to create a new User Provider which implements Illuminate\Contracts\Auth\UserProvider, specify it in AuthServiceProvider and update your auth config file accordingly.

Here are the links to the framework's default User Providers for reference :

1) DatabaseUserProvider

2) EloquentUserProvider




回答2:


I ended up coding my own Auth system...

Using session() and Input()



来源:https://stackoverflow.com/questions/41154660/laravel-auth-external-data-for-login-and-register

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!