0

My setup is:

  • aspnet core site hosting a Aurelia app
  • aspnet core api

I can easily config the hosting asp core site to do the auth with oauth2.

How can I pass a token to the hosted Aurelia app so it will be used for requests to the api?

Calin
  • 6,042
  • 5
  • 42
  • 74

1 Answers1

2

EDIT: Get an OAuth token using standard flow: On a high level, how does OAuth 2 work?

Pass it to the Aurelia client as a result of the API call to log in, or whatever. Should be done via https, ideally.

ORIG: You need to add an Authorization header to the request.

(Assuming you're using Aurelia-Fetch-Client)

Presumably, you have a bearer token, so the header could be configured like so:

httpClient.configure(config => {
  config
    .withBaseUrl('api/')
    .withDefaults({
      credentials: 'same-origin',
      headers: {
        'Accept': 'application/json',
        'X-Requested-With': 'Fetch',
        'Authorization': `Bearer ${getTokenFromLocalStore()}`
      }
    })

where getTokenFromLocalStore is your function that returns the token you retrieved earlier.

Michael Malone
  • 556
  • 4
  • 17
  • That is true, but how do I obtain this token in the first place? I am not suer about the flow of data here. – Calin Oct 23 '17 at 12:57