How to get Token of mvc in angular 6/ angular 9

 How to get Token of mvc in angular 6/ angular 9



For calling MVC Token we are divide process into three steps:-

Step1:-

getCSharpMVCToken(userData) {

    return new Promise((resolve, reject) => {

      const data = {

        'userName': this.loginForm.get('userName').value,

        'password': userData.uuid

      };

      this.authService.getCSharpMVCToken(data).then(tokenRes => {

        // this.userService.saveUserActivityLog(Constants.USER_ACTIVITIES.USER.NAME, Constants.NO_COMMENTS,

        //   Constants.USER_ACTIVITIES.OPERATIONS.LOGIN, Constants.NO_COMMENTS);

        return resolve(true);

      }).catch(err => {

        this.toggleSpinner(false);

        this.authService.logout();

        return reject(false);

      });

    });

  }

  

Step2:-

getCSharpMVCToken(data): Promise<any> {

        return new Promise((resolve, reject) => {

            if (this.alfAuthuthService.isEcmLoggedIn()) {

                this.apiService.getCSharpMVCToken(environment.CSharpMVCTokenApi, data).subscribe((res: any) => {

                    this.browserStorageService.setLocalStorageItem('CSharpMVCToken', res['access_token']);

                    return resolve(res);

                }, (err) => {

                    reject(err);

                });

            } else {

                reject(false);

            }


        });

           }

Step1:-

getCSharpMVCToken(URL, user: any) {

    const userData = 'username=' + user.userName + '&password=' + user.password + '&grant_type=password';

    const reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });

    const response = this.http.post(URL, userData, { headers: reqHeader }).pipe(map((res => {

      return res;

    })), catchError((error: any) => {

      return this.httpErrorHandler.handleError('api-service', error, URL);

    }));


    return response;

  }



No comments:

Post a Comment

Thank You For Your Great Contribution

Featured Post

how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys There is a way to find based of multiple key find duplicate records in ang...

Popular Posts