George Edwards
George Edwards

Reputation: 9229

Angular2 JWT Authentication - JWTs must come in 3 parts?

I am developing a simple MEAN stack app, using AngularJS 2. I am using passportJS with the jwt strategy + angular2-jwt helper library.

Here is my Angular Code, which deals with the login code. I have tested the API and it works (with postman).

//login.component.ts:
 onSubmit(credentials):void {
      console.log("on SUbmit here");
    this._userService.login(credentials.email, credentials.password)
    .subscribe((result) => {
      if (result) {
        console.log("Link to Todo?");
        this._router.navigate(['TodoComponent']);
      }
    });
  }

//user.service.ts:
  signUp(firstName, lastName, email, password) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

      let user = new URLSearchParams();
        user.set('email', email);
        user.set('password', password);
        user.set('firstName', firstName);
        user.set('lastName', lastName);

    return this._http
      .post('/signup', user.toString(), { headers })
      .map(res => res.json())
      .map((res) => {
        console.log(res.success);
        return res.success;
      });
  }

However, when I submit the login button , I get this error:

Uncaught (in promise): Error: JWT must have 3 parts

enter image description here

What should I do to ensure that the JWTs are given in the correct format and avoid these errors?

Upvotes: 1

Views: 8985

Answers (2)

Prakash Bariya
Prakash Bariya

Reputation: 1

I have same error. I solved error. Create new API in auth0. give Unique Identifier name. I took "NodeAPI" I mention below config code.

auth0 = new auth0.WebAuth({ 
             clientID: 'Hg3EhAWKgrPrX5UNGqFQA5vTbVGWF', 
             domain: 'xyz.auth0.com', 
             responseType: 'token id_token', 
             audience: 'NodeAPI', 
             redirectUri: 'http://localhost:4200/callback', 
             scope: 'openid' });

Happy to help you

Upvotes: 0

Benjamin M
Benjamin M

Reputation: 24527

What does your JWT look like? Your JWT should have 2 dots which split the string into 3 parts. Normally the 1st and 2nd part start with ey, which is the base64 encoded value for {.

You can paste it here: http://jwt.io/

This site can tell you if it's a valid JWT and can decode its contents, so you can prove that it correct.

Upvotes: 2

Related Questions