paulvanbladel / aurelia-auth

:key: Authentication plugin for aurelia
200 stars 74 forks source link

No Authorization header on getMe() #93

Closed ghost closed 8 years ago

ghost commented 8 years ago

I am trying to get my user data through the getMe() function, but it doesn't send the header.

config: var configForDevelopment = { httpInterceptor: true, loginOnSignup: false, baseUrl: '/', loginRedirect: '/', logoutRedirect: '/', signupRedirect: false, loginUrl: '/auth/login', signupUrl: '/auth/register', profileUrl: '/api/v2/users/me', loginRoute: '#/login', signupRoute: '#/register', tokenRoot: false, tokenName: 'token', tokenPrefix: 'aurelia', responseTokenProp: 'access_token', authHeader: 'Authorization', authToken: 'bearer', withCredentials: true, platform: 'browser', storage: 'localStorage' };

headers
paulvanbladel commented 8 years ago

and is the token sent for other requests you make?

michalru3ch commented 8 years ago

Hi guys.

I have similar problem and it seems to be caused by typo in authenticate.js. Please check line 77 - function getPayload tries to return parsed but you probably mean _parsed as defined on line 72.

Current implementation:

{
    key: 'getPayload',
    value: function getPayload() {

        var token = this.storage.get(this.tokenName);

        if (token && token.split('.').length === 3) {
            var base64Url = token.split('.')[1];
            var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');

            try {
                var _parsed = JSON.parse(decodeURIComponent(escape(window.atob(base64))));
            } catch (error) {
                return;
            }

            return parsed;
        }
    }
}

@J4ck4l0pe for now just replace it locally and we'll wait for update

RWOverdijk commented 8 years ago

@michalru3ch True. We've fixed that one already. A similar fix shouldn't be hard to write for this repository. Want to PR?

michalru3ch commented 8 years ago

You can do it; be my guest. I haven't cloned this library (just using it in my Aurelia project).

paulvanbladel commented 8 years ago

No problem, I'll fix it. Thanks for reporting the bug. paul.

paulvanbladel commented 8 years ago

fixed in 0.12.2

ghost commented 8 years ago

Thanks for fixing. I also called the getMe() before the fetchConfig.configure(). This might also have contributed to the problem.