Giter Club home page Giter Club logo

Comments (2)

bahuma20 avatar bahuma20 commented on September 4, 2024

Hi, yes this could be done via auth0. But right now there is no kind of admin interface or sth. like that... Are you working on a fork?

Fyi: there is a hosted version on https://mediathek.apps.bahuma.io/

from meine-mediathek.

sufius avatar sufius commented on September 4, 2024

I installed your repo locally, made it running. Already I'm digging into the new version (8.0.2) of auth0/auth0-php. But I'm still not sure if the token caching here is handled like in your authentication-method:

    public function authenticate(Request $request): PassportInterface
    {
        $jwt = substr($request->headers->get('Authorization'), 7);

        if (!$jwt || $jwt == '') {
            throw new CustomUserMessageAuthenticationException('Authorization token missing');
        }

        try {
            $token = $this->auth0->decode($jwt)->toArray();
        } catch (InvalidTokenException $e) {
            $this->logger->error($e->getMessage());
            throw new CustomUserMessageAuthenticationException('Unable to decode access token');
        }

        if (!$token['sub']) {
            throw new CustomUserMessageAuthenticationException('User ID could not be found in token');
        }

        $user = $this->userRepository->loadUserByIdentifier($token['sub']);
        // if user doesn't exist in database create a new one
        if ($user === null){
          $response = $this->auth0->authentication()->userInfo($jwt);
          // $requestBody = json_decode($response->getBody()->__toString(), true);
          if (HttpResponse::wasSuccessful($response)) {
            $userFromAuth0 = HttpResponse::decodeContent($response);
            if (!$userFromAuth0['email_verified']){
              throw new CustomUserMessageAuthenticationException('Email not yet verified. Please verify first.');
            }
            $newUser = new User();
            $newUser->setSub($userFromAuth0['sub']);
            $newUser->setEmail($userFromAuth0['email']);
            $newUser->setRoles($token['permissions']);
            $this->em->persist($newUser);
            $this->em->flush();
          } else {
            throw new CustomUserMessageAuthenticationException('User not found');
          }
        } else {
          $newUser = $user;
          $newUser->setRoles($token['permissions']);
        }

        return new SelfValidatingPassport(new UserBadge($token['sub'], function ($userId) use ($newUser) {
            return $newUser;
        }));
    }

from meine-mediathek.

Related Issues (1)

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.