1

I'm trying to pass a custom parameter to returnURL used in login page IdentityServer 4 from angular oidc-client.

Based on the parameter i receive from the returnURL I want to bypass the login website and redirect them to IDP. I'm intending to add the parameter to a specific page from angular and from there I want to redirect to login.

Below links talks about them but those I'm not able to follow. Can you guys please help. Thanks in advance.

Pass custom parameter to returnUrl used in login page Identity Server 4

https://github.com/IdentityServer/IdentityServer4/issues/909

C# AccountController.cs

public async Task<IActionResult> Login(string returnUrl)
{
    ViewBag.ReturnUrl = returnUrl;
    var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
    var vm = await _account.BuildLoginViewModelAsync(returnUrl);


    if (vm.IsExternalLoginOnly)
        return ExternalLogin(vm.ExternalProviders.First().AuthenticationScheme, returnUrl);

    return View(vm);
}

Angular auth.service.ts

const settings: any = {
  authority: environment.oauthUrl,
  client_id: 'website',
  redirect_uri: `${environment.applicationUrl}/auth.html`,
  post_logout_redirect_uri: `${environment.applicationUrl}`,
  response_type: 'id_token token',
  scope: 'openid profile email profile nucleus',

  silent_redirect_uri: `${environment.applicationUrl}/silent-renew.html`,
  automaticSilentRenew: true,

  monitorSession: true,
  checkSessionInterval: 2000,

  revokeAccessTokenOnSignout: true,
  filterProtocolClaims: true,
  loadUserInfo: true,

  changePasswordUrl: `${environment.oauthUrl}/Manage/ChangePassword?returnUrl=${environment.applicationUrl}`
};

I expect a parameter from returnurl and add a condition like this in Login method of AccountController.cs.

if (vm.IsExternalLoginOnly || returnUrl.Contains("customparameter"))
Jee Mok
  • 4,537
  • 7
  • 35
  • 66

1 Answers1

2

Incase if someone is looking for an answer. I have added route so that I can get clientid from angular app.

app.routes.ts

 { path: 'client/:id', component:ClientComponent }

In the client.component.ts

constructor(private authService: AuthService,private route: ActivatedRoute) { }

  ngOnInit() {
    const clientId=this.route.snapshot.params.id;
    if(clientId!=null) {
      this.authService.startSigninClient(clientId);
    }
  }

In the auth.service.ts

startSigninClient(clientid: string) {
    this.mgr.signinRedirect({
      extraQueryParams: {       
          client: clientid
      },
    })
      .catch((err) => {
        console.log(err);
      });
  }

Now when I open angular_app/client/clientid it redirects to client.component.ts and I'm calling signinredirect in which I'm adding extraQueryParams which is getting the value and sending a redirect_url from client oidc to dotnet authorization endpoint(accountcontroller.cs in my case) based on which I'm doing my required logic to handle different client logins and idps.