0

In an AngularJS Controller, I need to access the OAuth 2.0 Access Token sent with the HTTP GET Request to this particular View (and therefore Controller). I want to reuse this Access Token when calling other APIs, as part of the Authorization header (Authorization: Bearer ).

Can please someone tell me how I can access data in the GET Request header inside a Controller?

Any hint is highly appreciated. Thanks, Dominik

1 Answer 1

0

Are you making a GET request from within a controller? It's generally bad practice to do that. Instead:

  1. Create a service that will make the GET request (your access token can live as a private service property). The service can have multiple methods that use the same token.
  2. Inject the service in your controller and call the service method you need to pass the data to your controller.

This way, you can store your access token in one place, and re-use it for all your data calls.

More on services: https://docs.angularjs.org/guide/services

To help you further, please give more detail (including code) about what you're doing now and what you'd like to achieve.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, and even if it's bad practice, it's just for a small PoC app. :-) What I wanna do is the following: - Extract the Bearer token from the GET Request to this Controller (or Service) - Store the Bearer token temporarily - Add the Bearer token to a new GET Request (AuthZ header) Unfortunatley, I have no code to share.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.