Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

defaultHeadersForTokenRequests not working for updateToken() #358

Closed
pllamena opened this issue Jul 10, 2017 · 7 comments
Closed

defaultHeadersForTokenRequests not working for updateToken() #358

pllamena opened this issue Jul 10, 2017 · 7 comments

Comments

@pllamena
Copy link

pllamena commented Jul 10, 2017

Hello,

@groenlid - @RWOverdijk suggested I should pin you to this issue.

Setting the defaultHeadersForTokenRequests seems to work for the login() method, but not for updateToken(). All the parameters are missing from the updateToken request, which also happens for the initial token request made by login() if I remove the defaultHeadersForTokenRequests: {'Content-Type': 'application/x-www-form-urlencoded'} line.

Here is my set up:

foo
  .plugin('aurelia-api', configure => {
    configure
      .registerEndpoint('auth', environment.apiEndpoint, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
      .registerEndpoint('protected-api', environment.apiEndpoint)
      .setDefaultEndpoint('protected-api')
  })
  .plugin('aurelia-authentication', baseConfig => {
    baseConfig.configure({
      endpoint                      : 'auth',
      configureEndpoints            : ['auth', 'protected-api'],
      defaultHeadersForTokenRequests: {'Content-Type': 'application/x-www-form-urlencoded'},
      loginUrl                      : 'token',
      authHeader                    : 'Authorization',
      authTokenType                 : 'Bearer',
      httpInterceptor               : true,
      accessTokenProp               : 'access_token',
      useRefreshToken               : true,
      clientId                      : 'XXXXXXXX',
      refreshTokenUrl               : 'token',
      refreshTokenProp              : 'refresh_token',
      refreshTokenSubmitProp        : 'refresh_token',
      autoUpdateToken               : true,
      storage                       : 'localStorage',
      loginRedirect                 : '#/home',
      logoutRedirect                : '#/home',
      getExpirationDateFromResponse : (response => {
        if (response && response.expires_in) {
          return (new Date().getTime() + response.expires_in * 1000) / 1000
        }
      })
    })
  })

If you login and refresh the page, updpateToken() is called, but since it doesn't attach any parameters to the token request, authentication fails and the user gets logged out.

Am I missing something? Please let me know if more details are needed!

Thank you!

pllamena referenced this issue Jul 10, 2017
Add some default headers to the baseConfig that will be appended when using .login() and .refreshToken(). This is to support IdentityServer 4 with the openId spec http://openid.net/specs/openid-connect-core-1_0.html#TokenRequest.
Gives us the posibility to use application/x-www-form-urlencoded as content-type.
@RWOverdijk
Copy link
Member

I've slightly changed your description (removed some typos and made the code snippet prettier).

@groenlid you worked on this, correct? Do you have any input on this issue? :)

@pllamena
Copy link
Author

Thank you, @RWOverdijk!

I have been trying to find a work around this week, but I haven't got anywhere with it yet.

Any input will be much appreciated! :)

Thank you again!

@RWOverdijk
Copy link
Member

I think @groenlid is mia. I'll pin this to my own inbox and see if I can find time to tackle this.

@pllamena
Copy link
Author

Thank you @RWOverdijk !

@RWOverdijk
Copy link
Member

If you find the solution in the meantime, that'd be even better obviously :D

@pllamena
Copy link
Author

pllamena commented Aug 1, 2017

Hi @RWOverdijk,

Good news - defaultHeadersForTokenRequests works! Since the token endpoint was working outside the Aurelia App & removing defaultHeadersForTokenRequests broke the initial login (which was only due the default format being JSON), I had assumed it was the front end that was causing the error. Turned out I had to make adjustments in the token generation for it to accept requests from the App and everything works now.

Thank you for responding to my comment and the issue!

@pllamena pllamena closed this as completed Aug 1, 2017
@RWOverdijk
Copy link
Member

Oh I'm glad you solved it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants