2017-12-06 27 views
0

, 나는이 같은 루트 그룹을 요청합니다. 클라이언트 자격 증명 부여를 구현할 때 나는 separate middleware is necessary이라는 것을 발견했습니다. auth:api 미들웨어는 예외를 발생시키기 때문에이 중 하나의 권한 부여 토큰을 가진 요청이이 경로에 액세스하기를 원하기 때문에 충돌이 발생합니다.사용하여 클라이언트 자격 증명 미들웨어 내 <code>routes/api.php</code> 파일에서

내가 발견 한 것은 클라이언트 신임장 미들웨어를 사용하는 것이 두 가지를 모두 검증하는 것인데, 그렇게하는 것이 나쁜 의미인지 여부는 확실하지 않습니다.

미들웨어를 우회하여이를 Laravel\Passport\Http\Middleware\CheckClientCredentials으로 바꾸는 데 문제가 있습니까?

답변

0

명백한 커다란 단점은 클라이언트 자격 증명이 JWT 토큰에 사용자 정보가없는 것처럼 보입니다. 이로 인해 요청에 대한 사용자 확인자가 request()->user()에 대한 호출에 대해 null을 반환합니다. Laravel\Passport\Guards\TokenGuard::authenticateViaBearerToken에서이 null을 반환되었다

// If the access token is valid we will retrieve the user according to the user ID 
// associated with the token. We will use the provider implementation which may 
// be used to retrieve users from Eloquent. Next, we'll be ready to continue. 
$user = $this->provider->retrieveById(
    $psr->getAttribute('oauth_user_id') 
); 

$psr->getAttribute을 추적하는 것은 League\OAuth2\Server\AuthorizationValidators\BearerTokenValidator::validateAuthorization를 알려준 :

oauth_user_id 제외 토큰, $token에 특허 청구 범위를 통해 올바르게 설정되고 있었다 속성
// Return the request with additional attributes 
return $request 
    ->withAttribute('oauth_access_token_id', $token->getClaim('jti')) 
    ->withAttribute('oauth_client_id', $token->getClaim('aud')) 
    ->withAttribute('oauth_user_id', $token->getClaim('sub')) 
    ->withAttribute('oauth_scopes', $token->getClaim('scopes')); 

모든 내 경우는 Lcobucci\JWT\Token의 사례입니다. 따라서 클라이언트 자격 증명 미들웨어 만 사용하면 지정된 user_id의 oauth 클라이언트를 사용하는 경우에도 단일 경로 집합을 갖는 좋은 해결책이 아닙니다.