Skip to content

Conversation

@baijunyao
Copy link
Contributor

  1. Sometimes we need use setUserIdAttribute, but setRawAttributes cannot trigger Mutator
  2. Use model instead of DB

@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

@baijunyao
Copy link
Contributor Author

I want encrypt the user_id in access_token.
image
Passport is flexible, I only need to do two things.

  1. Extend src/Http/Controllers/ApproveAuthorizationController.php
public function approve(Request $request)
{
    return $this->withErrorHandling(function () use ($request) {
        $authRequest = $this->getAuthRequestFromSession($request);
+       $user_id = $authRequest->getUser()->getIdentifier();
+       $user = new User(Crypt::encryptId($user_id));
+       $authRequest->setUser($user);

        return $this->convertResponse(
            $this->server->completeAuthorizationRequest($authRequest, new Psr7Response)
        );
    });
}
  1. Extend /src/AuthCode.php
+    public function setUserIdAttribute($value)
+    {
+        $this->attributes['user_id'] = Crypt::decryptId($value);
+    }

But in /src/Bridge/AuthCodeRepository.php persistNewAuthCode method use setRawAttributes store data.

    public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity)
    {
        
        $attributes = [
            'id' => $authCodeEntity->getIdentifier(),
            'user_id' => $authCodeEntity->getUserIdentifier(),
            'client_id' => $authCodeEntity->getClient()->getIdentifier(),
            'scopes' => $this->formatScopesForStorage($authCodeEntity->getScopes()),
            'revoked' => false,
            'expires_at' => $authCodeEntity->getExpiryDateTime(),
        ];

        Passport::authCode()->setRawAttributes($attributes)->save();
    }

setRawAttributes cannot trigger setUserIdAttribute .

I think other people may also need some features of the model.
So I created AuthCodeRepository.php file.

@driesvints
Copy link
Member

@baijunyao can you please first create an issue with the feature request so we can discuss it?

@baijunyao
Copy link
Contributor Author

Okay, thanks . #908

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants