Created
November 22, 2018 16:44
-
-
Save mjordan/6368d0d07047528d85b2b1dd7a997b10 to your computer and use it in GitHub Desktop.
Using JWT for internal REST calls in Drupal 8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Construct Authorization header using jwt token. | |
$container = \Drupal::getContainer(); | |
$jwt = $container->get('jwt.authentication.jwt'); | |
$auth = 'Bearer ' . $jwt->generateToken(); | |
$client = \Drupal::httpClient(); | |
$options = [ | |
'auth' => [], | |
'headers' => ['Authorization' => $auth], | |
'form_params' => [] | |
]; | |
$response = $client->request('GET', 'http://localhost:8000/node/' . $nid . '/media?_format=json', $options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!! You save me a lot of days! :)