Calin
Calin

Reputation: 6847

Oauth2 for Aurelia hosted in asp .net core

My setup is:

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?

Upvotes: 0

Views: 175

Answers (1)

Michael Malone
Michael Malone

Reputation: 616

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.

Upvotes: 2

Related Questions