Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jwt_auth_bad_auth_header #3

Closed
Pycroyal opened this issue Sep 25, 2015 · 8 comments
Closed

jwt_auth_bad_auth_header #3

Pycroyal opened this issue Sep 25, 2015 · 8 comments

Comments

@Pycroyal
Copy link

Hello,

Thanks for your plugin.

When i try your sample request with angular i've this response:
"code": "jwt_auth_bad_auth_header",
"message": "Authorization header malformed.",
"data": {
"status": 403
}

What's wrong ?

@Pycroyal
Copy link
Author

How can I control the header ?

@Tmeister
Copy link
Owner

You need to be sure you send the proper token along the header

app.config( function( $httpProvider ) {
  $httpProvider.interceptors.push( [ '$q', '$location', '$cookies', function( $q, $location, $cookies ) {
    return {
      'request': function( config ) {
        config.headers = config.headers || {};
        //Assume that you store the token in a cookie.
        var globals = $cookies.getObject( 'globals' ) || {};
        //If the cookie has the CurrentUser and the token
        //add the Authorization header in each request
        if ( globals.currentUser && globals.currentUser.token ) {
          config.headers.Authorization = 'Bearer ' + globals.currentUser.token;
        }
        return config;
      }
    };
  } ] );
} );

You need to verify the content in this line

config.headers.Authorization = 'Bearer ' + globals.currentUser.token;

In this example i asume that you are using cookies to store the token.

@Tmeister
Copy link
Owner

I'm sorry but this is not the place to ask how to store a cookie or how to consume the REST API

This plugin only give you the ability to sign a request and authenticate the user using the JWT token.

You can find more information on how to use the WP REST API in the documentation site

@Pycroyal
Copy link
Author

OK Sorry.
I found another solution.

@h3ndro
Copy link

h3ndro commented Feb 17, 2016

hi PyNApo, would you share your solution?i'm facing the same problem

@h3ndro
Copy link

h3ndro commented Feb 18, 2016

nevermind,..i got it working

@medrockstar
Copy link

medrockstar commented Apr 15, 2016

hi,

I have the same problem with Postman in my local server.

Tks,

@sirdowan
Copy link

sirdowan commented Feb 15, 2017

@h3ndro @PyNApo and what was your solution?? screenshot of Postman or something?
Thanks!

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

No branches or pull requests

5 participants