Open Closed

How to add extra parameter or extra Httpheader in Login method #2026


User avatar
0
kaustubh.kale@ness.com created

ABP Framework version: v4.3.1 UI type: Angular DB provider: EF Core Tiered (MVC) or Identity Server Separated (Angular): no / yes Exception message and stack trace: N.A Steps to reproduce the issue:" N.A

We want to add HttpHeader in Login method call . how we can add one more httpHeader in below request .Currently We paasing Username and Password .

We are using Angular 11 for client side . Please find below implementation of login method.

constructor(private authService: AuthService)
var loginParams = {
      username: this.form.get('username').value,
      password: this.form.get('password').value
    }
    
this.authService
      .login(loginParams)
      .pipe(
        catchError((err) => {
          return err;
        }),
        finalize(() => (this.inProgress = false))
      )
      .subscribe(() => {

        var tokeParams = {
          fullToken: this.oauthService.getAccessToken()
        }
       

        });
      });
      
  }

3 Answer(s)
  • User Avatar
    0
    kaustubh.kale@ness.com created

    Hi Team any update on above?

  • User Avatar
    0
    Mehmet created

    Hi,

    You can use a method like below:

      login(params: LoginParams): Observable<any> {
        const router = this.injector.get(Router);
        const tenant = this.sessionState.getTenant();
    
        return from(
          this.oAuthService.fetchTokenUsingPasswordFlow(
            params.username,
            params.password,
            new HttpHeaders({ ...(tenant && tenant.id && { __tenant: tenant.id }) }), // add headers here
          ),
        ).pipe(
          switchMap(() => this.appConfigService.get()),
          tap(res => {
            this.configState.setState(res);
            this.setRememberMe(params.rememberMe);
            if (params.redirectUrl) router.navigate([params.redirectUrl]);
          }),
        );
      }
    

    Resource: https://github.com/abpframework/abp/blob/73723bfa26b6709fbf908145df8aece8d25fe5bf/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts#L190-L208

  • User Avatar
    0
    Mehmet created

    When you update your app to v5.0, you cannot use setState method of the ConfigState. See that code to learn how it can be done in v5.0.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11