KillerCookie's avatar

Laravel application with OAUTH2-Auth (as OAuth2 Client)

How can I tell a Laravel app that it is connecting to an existing OAuth2 server using this as a login?

I already have the relevant access data such as ClientID, password, etc.

Is there a suitable package for this?

0 likes
3 replies
bugsysha's avatar

Use Laravel Socialite package. You can check this website to see if there is an implementation for server that you need.

1 like
KillerCookie's avatar

ok thanks @bugsysha. You helped me a little. Now I've created my own "provider" for my oauth2 server, but it didn't work. Do you have any idea?

I used the ProviderGenerator from Github and the SocialiteManager. However, when I try to use it, I get the following error:

Driver [name] not supported. 

Here is my web.php snippet

Route::get('/auth/redirect', function () {
    return Socialite::driver('test')->redirect();
});

Route::get('/auth/callback', function () {
    $user = Socialite::driver('test')->user();

    // OAuth 2.0 providers...
    $token = $user->token;
    $refreshToken = $user->refreshToken;
    $expiresIn = $user->expiresIn;

    // All providers...
    $user->getId();
    $user->getName();
    $user->getEmail();
});

app.php

SocialiteProviders\Manager\ServiceProvider::class,
SocialiteProviders\Generators\GeneratorsServiceProvider::class,

service.php

'test' => [
        'client_id' => env('secret'),
        'client_secret' => env('secret'),
        'redirect' => getenv('URL') . '/login',
    ]
bugsysha's avatar
bugsysha
Best Answer
Level 61

@killercookie you can't just put a random driver name and expect it to work.

Here is an article that explains how to create new providers.

Please or to participate in this conversation.