Commit 63185dac authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Handled configurable scope in token issuer

parent a6b63bee
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -117,7 +117,24 @@ class TokenBuilder {
            'aud' => $audience
        );

        $conf = $this->getTokenIssuerConfig($audience);
        if (property_exists($conf, 'aud')) {
            $payload['aud'] = $conf->aud;
        }
        if (property_exists($conf, 'scope')) {
            $payload['scope'] = $conf->scope;
        }

        return JWT::encode($payload, $keyPair->privateKey, $keyPair->alg, $keyPair->keyId);
    }

    private function getTokenIssuerConfig($audience) {
        foreach ($this->locator->config->tokenIssuer->services as $service) {
            if ($service->id === $audience) {
                return $service;
            }
        }
        throw new \Exception("Unable to find configuration for " . $audience);
    }

}