public async Task <IActionResult> InviteUsingInvitationCode(string companyId) { if (!string.IsNullOrEmpty(this.userInvitationApiUrl)) { var client = this.httpClientFactory.CreateClient(); var invitationCodeRequest = new { CompanyId = companyId }; var invitationCodeRequestContent = new StringContent(JsonConvert.SerializeObject(invitationCodeRequest), Encoding.UTF8, "application/json"); var response = await client.PostAsync(this.userInvitationApiUrl, invitationCodeRequestContent); response.EnsureSuccessStatusCode(); var invitationCodeResponseValue = await response.Content.ReadAsStringAsync(); dynamic invitationCodeResponse = JsonConvert.DeserializeObject(invitationCodeResponseValue); var invitationCode = (string)invitationCodeResponse?.invitationCode; var authenticationRequestUrl = Url.Action("Register", "Account", null, "https" /* This forces an absolute URL */); var model = new AccountInvitationViewModel { CanInviteUsingClientAssertion = !string.IsNullOrWhiteSpace(this.signingSecret), CanInviteUsingInvitationCode = !string.IsNullOrWhiteSpace(this.userInvitationApiUrl), CompanyId = companyId, AuthenticationRequestUrl = authenticationRequestUrl, InvitationCode = invitationCode }; return(View(nameof(Invite), model)); } return(RedirectToAction(nameof(Invite))); }
public IActionResult Invite() { var model = new AccountInvitationViewModel { CanInviteUsingClientAssertion = !string.IsNullOrWhiteSpace(this.signingSecret), CanInviteUsingInvitationCode = !string.IsNullOrWhiteSpace(this.userInvitationApiUrl) }; return(View(model)); }
public IActionResult InviteUsingClientAssertion(string email, int validDays = 30) { if (!string.IsNullOrEmpty(email)) { // Generate an invitation link for the requested email address by generating a self-issued token and sending that to the "Register" action. var expiration = TimeSpan.FromDays(validDays); // Defines how long the invitation is valid. var claims = new[] { new Claim("verified_email", email) // This claim maps to the extension attribute registered in AAD B2C which is used in the custom invitation policy. }; var selfIssuedToken = CreateSelfIssuedToken(expiration, claims, this.signingSecret); var authenticationRequestUrl = Url.Action("Register", "Account", new { client_assertion = selfIssuedToken }, "https" /* This forces an absolute URL */); var model = new AccountInvitationViewModel { CanInviteUsingClientAssertion = !string.IsNullOrWhiteSpace(this.signingSecret), CanInviteUsingInvitationCode = !string.IsNullOrWhiteSpace(this.userInvitationApiUrl), Email = email, AuthenticationRequestUrl = authenticationRequestUrl }; return(View(nameof(Invite), model)); } return(RedirectToAction(nameof(Invite))); }