Laravel: how to check if a user is logged with oauth?

I'm implementing social login with oauth using the package oauth-4-laravel in my laravel application. Following the instructions of the package I'm able to connect with facebook or with google. Now I don't want to store user data but still I want a user to access a page only if legged with facebook or google. I have to check if a user is logged with oauth in a route filter. Something like this

Route::filter('auth', function()
    if (!OAuth::check()) return Redirect::guest('login');

How do I do that? Or should I use another method?


Typically even when you use OAuth as authentication method, your application will still have to store user_id or name, and their email isn't it? If so, you can still apply laravel authentication like so:

//After the OAuth authentication
$user = User::where('email', $email)->firstOrFail(); //$email is the email returned from OAuth

//without acessing DB
$user = new User();
$user->email = $email; //this is an eg, can be replace with whatever user's properties you have.

Auth::login($user); //login the user using laravel

//To logout user manually

//In your filters.php
Route::filter('auth', function()
    if (Auth::guest()) 
        return Redirect::guest('login');

Need Your Help

vestal_versions and htmldiff question of reversion

ruby-on-rails refactoring versioning vestal-versions reversion

I'm guessing there's probably an easier way to do what I'm doing so that the code is less unwieldy.

Android: Right-Aligning ImageView in LinearLayout

android android-layout android-linearlayout android-imageview

The imageView is not getting right-aligned in this linearlayout (If it matters this LinearLayout is actually a row in a list).