artdarek / oauth-4-laravel

OAuth Service Provider for Laravel 4
683 stars 216 forks source link

Best way to get avaliable user tokens. #67

Open dmitriy-sqrt opened 10 years ago

dmitriy-sqrt commented 10 years ago

Hello and thanks for a nice laravel package (:

I`m creating a simple auth system with different providers on my site.

Is there a nice way to get some token that the user has (when i dont know which provider user used to sign_in)? I then want to look it in the database and assign a corresponding profile to my user.

I'm currently thinking of:

foreach ($ouath_providers as $provider) { $provider = OAuth::consumer($provider); $provider->getStorage()->retrieveAccessToken(...); ... }

which doesnt look great. Thanks for your feedback. (:

samvasko commented 10 years ago

AFAIK there is no other way. :disappointed: . How would like the API to look like?

dmitriy-sqrt commented 10 years ago

Well, some elven magic could bring as the token from session, if we've stored only one token.. But ok then (: Thanks for your quick reply!

dmitriy-sqrt commented 10 years ago

Ended up with this for now:

        $token = '';
        foreach (Config::get('oauth-4-laravel::consumers') as $provider_name => $provider)
        {
            $service = OAuth::consumer($provider_name);
            if ($service->getStorage()->hasAccessToken($provider_name))
            {
                $token = $service->getStorage()->retrieveAccessToken($provider_name)->getAccessToken();
                break;
            }
        }

Just using the first found token and considering it the only one.