Code Monkey home page Code Monkey logo

Comments (9)

simplenotezy avatar simplenotezy commented on June 8, 2024

Interesting question - I was wondering the same thing. The ProviderUserDetails way of doing it seems very static.

from eloquent-oauth.

ockam avatar ockam commented on June 8, 2024

+1

from eloquent-oauth.

ockam avatar ockam commented on June 8, 2024

Worked my way around this but this is not pretty. Not sure it’s the appropriate way to deal with this but I post it anyway if it can hint other users on a workaround.

I extended each provider (in my case, I only need LinkedIn) in my app namespace and overrided the $profileFields property and the getUserDetails function.

I also extended EloquentOAuthServiceProvider and overrided the $providerLookup property to register my new provider.

Then you need to register this service provider instead of the original one in config/app.php

from eloquent-oauth.

adamwathan avatar adamwathan commented on June 8, 2024

You're right, this must've been an oversight on my part during a refactoring, I'm sure this was more straightforward at some point.

Going to look into this and see what I can do :) Originally you just needed to say $details->customField and it would work, if I remember correctly. Clearly not the case now, heh...

from eloquent-oauth.

adamwathan avatar adamwathan commented on June 8, 2024

Alright, I remember why I originally had that scopes option.

Since this package retrieves an access token you can use for later requests to the provider's API, I wanted to make sure that the token that came back had any additional scopes you might need. It wasn't meant to handle any additional data that came back from the initial request for a user's profile information.

That being said, I've pushed an update that stores all raw data that comes back from that request on the ProviderUserDetails object, so it can be accessed however you need:

$details->raw()['birthday'];

...would get you what you need now :)

from eloquent-oauth.

ockam avatar ockam commented on June 8, 2024

Hi Adam,

thanks for the raw feature, but that doesn’t allow us to add additional fields to the $profileFields property of the provider.

Can you add a config for that?

from eloquent-oauth.

ockam avatar ockam commented on June 8, 2024

Only need to add the following line to the constructor of the Provider class:

        if (isset($config['profileFields'])) {
            $this->profileFields = array_merge($this->profileFields, $config['profileFields']);
        }

from eloquent-oauth.

adamwathan avatar adamwathan commented on June 8, 2024

Ah you are specifically talking only about the LinkedIn Provider it seems, didn't catch that before. None of the other providers have that property and it's really just a special case for LinkedIn's API.

I don't think I'm really interested in adding too much built-in configuration for that sort of thing, as one of the main goals of the package is to handle normalization between providers of a specific set of common fields.

I think your original solution is actually an excellent and clean solution for your needs. Just extend the LinkedIn provider, add the fields you need (either hardcore or through config), and register it with your own service provider.

Custom LinkedIn provider:

class CustomLinkedInProvider extends LinkedInProvider
{
    protected $profileFields = [
        'id',
        'first-name',
        'last-name',
        'email-address',
        'picture-url',
        'plus',
        'any',
        'others',
        'you',
        'might',
        'need',
    ];
}

Custom service provider:

class CustomSocialLoginServiceProvider extends EloquentOAuthServiceProvider {

    protected $providerLookup = [
        'linkedin' => 'Your\\Custom\\LinkedInProvider',
    ];
}

That's literally the whole thing 👍

from eloquent-oauth.

ockam avatar ockam commented on June 8, 2024

Understood. Thanks for the sample code.

from eloquent-oauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.