Code Monkey home page Code Monkey logo

Comments (5)

stevensajw avatar stevensajw commented on September 6, 2024

Maybe something like this would work? Get the data from the token and merge it with the existing data. Don't know if there are any edge cases (empty idtoken?) we would need to test.

 
  public function retrieveUserInfo(OidcTokens $tokens): OidcUserData
  {
    // Set the authorization header
    $headers = ["Authorization: Bearer {$tokens->getAccessToken()}"];

    // Retrieve the user information and convert the encoding to UTF-8 to harden for surfconext UTF-8 bug
    $jsonData = $this->urlFetcher->fetchUrl($this->getUserinfoEndpoint(), null, $headers);
    $jsonData = mb_convert_encoding($jsonData, 'UTF-8');

    // Read the data
    $userInfoData = json_decode($jsonData, true);

    // Get the data from the id_token
     $tokenData = $this->jwtHelper->decodeJwt($tokens->getIdToken(), 1);
     $tokenData = json_decode(json_encode($tokenData), true);
     $data = array_merge($tokenData, $userInfoData);
   
    // Check data due
    if (!is_array($data)) {
      throw new OidcException('Error retrieving the user info from the endpoint.');
    }

    return new OidcUserData($data);
  }

from symfony-oidc.

bobvandevijver avatar bobvandevijver commented on September 6, 2024

Well, what you're looking is indeed not possible with the current implementation, so you didn't miss something obvious. Only Microsoft did by leaving out the most important user information from the User Info endpoint 😄

To me option 1 seems best, as that would be the nicest point of integration in my opinion without processing the user info data. You can adjust the OidcAuthenticator to retrieve the $userIdentifier from either the $userData as it does now, or to retrieve it from the id token when configured. A new method to retrieve the identifier would be best.

I assume you still need access to the user info to be able to load the rest of the user information, right?

Are you up for a PR? You can look at how the userIdentifierProperty/user_identifier_property has been implemented, and adjust it for a new useIdTokenForUserIdentifier. The retrieval of the correct JWT part can be added to the OidcJwtHelper class, and maybe even refactor this line to use it: https://github.com/Drenso/symfony-oidc/blob/master/src/OidcClient.php#L445.

from symfony-oidc.

stevensajw avatar stevensajw commented on September 6, 2024

Hi Bob,

That seems like fun. I'll try a PR, I have time this Wednesday, so will look into it then.

Thanks,

Albert-Jan

from symfony-oidc.

bobvandevijver avatar bobvandevijver commented on September 6, 2024

Fixed with #38, thank you @stevensajw 👍🏻 (and tagged as 2.10.0)

from symfony-oidc.

stevensajw avatar stevensajw commented on September 6, 2024

Learned a lot, thank you :-)

from symfony-oidc.

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.