0

I generate a token in the net core needed to change the password, it is sent to the email, then after clicking the link in the email it moves to the front page in the angular, which performs an API request for confirmation of the email address, unfortunately the problem is that the token the API gets changed, ie there is no + what you see in the two above tokens, that is, one token. Its first version is the version generated in the API, and the second version is the token that reaches from the front to the API. I do not know how to deal with it. I know that the problem lies on the front because it's from him requesting to activate the email.

Generated token:

CfDJ8BUjSrrXE9xEiTFPyVuPcKDsxGyY81gv4tiZ+Y8Ntrx6PPMGmhqgpDUI7Kbpuc5PZz/YcudD/SWYSGqeniyPlpZGxfgclYwNtm/3Ef3uHUTajlrs61yMPEVA/g0yLWzaHkkxitckXYdclgK8RyUEA3s4rnJ9xP1ihHlkPFZNgn5cC4q/x/oSgjxBAysGaoBM192TfS9dhGDeKR4YqYBVQEYQKnmtljkdKdgt21z0d4zGaW0rHBOn/GtLIrGXwcokng==

The token obtained

CfDJ8BUjSrrXE9xEiTFPyVuPcKDsxGyY81gv4tiZ Y8Ntrx6PPMGmhqgpDUI7Kbpuc5PZz/YcudD/SWYSGqeniyPlpZGxfgclYwNtm/3Ef3uHUTajlrs61yMPEVA/g0yLWzaHkkxitckXYdclgK8RyUEA3s4rnJ9xP1ihHlkPFZNgn5cC4q/x/oSgjxBAysGaoBM192TfS9dhGDeKR4YqYBVQEYQKnmtljkdKdgt21z0d4zGaW0rHBOn/GtLIrGXwcokng==

My code to send request:

 ngOnInit() {
    this.activateRouted.queryParamMap.subscribe(params => {
    let code = params.get("confirmationToken");
    let userId = params.get("id");

      if (code != null && userId != null){
        this.userService.confirmEmail(userId,code).subscribe((data: any) => this.confirmSuccess(data), 
        (err: HttpErrorResponse) => this.confirmError(err));
      }
    });
  }

confirmEmail method from userService:

  public confirmEmail(userId: string, code: string) {
    const req = this.apiService.get(`/api/register/confirm/?id=${userId}&confirmationToken=${code}`);
    return req;
  }
PawelC
  • 1,128
  • 3
  • 21
  • 47
  • Try this @PawalC. I think this is what you are looking for. You need to decode your token. https://stackoverflow.com/a/49153118/7109092 – Muhammad Ahsan Feb 21 '19 at 12:12
  • 1
    You are not encoding your token before submitting it. In url encoding, spaces are encoded as `+`. So in order to send `+` you need to encode it as `%2B` – Tseng Feb 21 '19 at 12:17
  • @Ahsan not working with UrlDecode and UrlEncode :( – PawelC Feb 21 '19 at 12:29

1 Answers1

0

If someone had a similar problem, I give the solution: encodeURIComponent to token param :) Now all works fine,

public confirmEmail(userId: string, code: string) {
    const req = this.apiService.get(`/api/register/confirm/?id=${userId}&confirmationToken=${encodeURIComponent(code)}`);
    console.log(req);
    return req;
  }
PawelC
  • 1,128
  • 3
  • 21
  • 47