Zn4rK / php-withings

PSR-FIG Compatible Withings Body metrics Services API written in PHP.
17 stars 14 forks source link

Socialite 3 compatibility ? #25

Closed u1735067 closed 6 years ago

u1735067 commented 6 years ago

Hello, if php-withings is compatible with socialite 3 (but I have no idea about this, nor I know what changed since v2), could you mark it as compatible / allow socialite 3 as dependency ("~2.0 || ~3.0" I guess) ? Thanks :)

Zn4rK commented 6 years ago

I don't know if the library is compatible with Socialite 3, you'll have to test that for your self.

Socialite isn't actually required by the package, and that line in composer.json should probably be rewritten to be a suggestion instead of a require...

You are more than welcome to do a PR with this fix after you've confirmed if it works with Socialite 3.

u1735067 commented 6 years ago

I made the change in https://github.com/Alex131089/php-withings/tree/dev-compat-socialite3 and found the way to use my fork easily (https://stackoverflow.com/questions/13498519/how-to-require-a-fork-with-composer) :

    "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/Alex131089/php-withings"
            }
    ],
    [...]
    "paxx/withings": "dev-dev-compat-socialite3@dev"

(note: this is more for personal reference than explanation :) )

I'll let you know if it's ok when I'm more confortable with Socialite (first use actually ;) ). Thanks for the answer.

u1735067 commented 6 years ago

Took me an hour to figure out how to use it with Socialite (not intended to be extended, their want SocialiteProviders for this, so not documented), but I got it working. So it seems there's no incompatibility.

Method used :

namespace App\Http\Controllers;

use Socialite; use \Paxx\Withings\Provider\Withings as WithingsProvider; use \Paxx\Withings\Server\Withings as WithingsServer;

class AppSocial extends Controller { public function withingsInit() { Socialite::extend('withings', function($app) { $config = $app['config']['services.withings']; return new WithingsProvider( $app['request'], new WithingsServer(Socialite::formatConfig($config)) ); }); }

public function withingsRedirect(Request $request)
{
    $this->withingsInit();
    return Socialite::driver('withings')->redirect();
}

public function withingsCallback(Request $request)
{
    $this->withingsInit();
    $user = Socialite::driver('withings')->user();

    dd($user, $user->getRaw());
}

}


Both the `redirect()` and the `user()` worked.

`composer info`: 

laravel/framework v5.4.32 The Laravel Framework. laravel/socialite v3.0.7 Laravel wrapper around OAuth 1 & OAuth 2 libraries. league/oauth1-client 1.7.0 OAuth 1.0 Client Library guzzlehttp/guzzle 6.3.0 Guzzle is a PHP HTTP client library guzzlehttp/oauth-subscriber 0.3.0 Guzzle OAuth 1.0 subscriber paxx/withings dev-dev-compat-socialite3 c106f98 Withings API - Withings Body metrics Services API http://www.withings.com/api



I don't know is this is the right integration method, but if it is I think it should be documented ?
Want the composer.json pull request ?
Zn4rK commented 6 years ago

Nice.

The only recommendation I have is that you do the extension in your AppServiceProvider instead.

(this part)

 Socialite::extend('withings', function($app) {
            $config = $app['config']['services.withings'];
            return new WithingsProvider(
                $app['request'],
                new WithingsServer(Socialite::formatConfig($config))
            );
        });
u1735067 commented 6 years ago

I see :) Thanks for the feedback. So I guess the issue is resolved : it is compatible with Socialite 3.