private async Task <Tenant> SignUpTenantAsync(BaseControlContext context, TenantManager tenantManager) { Guard.ArgumentNotNull(context, nameof(context)); Guard.ArgumentNotNull(tenantManager, nameof(tenantManager)); var principal = context.AuthenticationTicket.Principal; var issuerValue = principal.GetIssuerValue(); var tenant = new Tenant { IssuerValue = issuerValue, Created = DateTimeOffset.UtcNow }; try { await tenantManager.CreateAsync(tenant) .ConfigureAwait(false); } catch (Exception ex) { _logger.SignUpTenantFailed(principal.GetObjectIdentifierValue(), issuerValue, ex); throw; } return(tenant); }
/// <summary> /// Extension method to see if the current process flow is the sign up process. /// </summary> /// <param name="context">BaseControlContext from ASP.NET.</param> /// <returns>true if the user is signing up a tenant, otherwise, false.</returns> internal static bool IsSigningUp(this BaseControlContext context) { Guard.ArgumentNotNull(context, nameof(context)); // Note - Due to https://github.com/aspnet/Security/issues/546, we cannot get to the authentication properties // from the context in the RedirectToAuthenticationEndpoint event to check for sign up. This bug is currently // slated to be fixed in the RC2 timeframe. When this is fixed, remove the workaround that checks the HttpContext string signupValue; object obj; // Check the HTTP context and convert to string if (context.HttpContext.Items.TryGetValue("signup", out obj)) { signupValue = (string)obj; } else { // It's not in the HTTP context, so check the authentication ticket. If it's not there, we aren't signing up. if ((context.AuthenticationTicket == null) || (!context.AuthenticationTicket.Properties.Items.TryGetValue("signup", out signupValue))) { return(false); } } // We have found the value, so see if it's valid bool isSigningUp; if (!bool.TryParse(signupValue, out isSigningUp)) { // The value for signup is not a valid boolean, throw throw new InvalidOperationException($"'{signupValue}' is an invalid boolean value"); } return(isSigningUp); }
/// <summary> /// Extension method to see if the current process flow is the sign up process. /// </summary> /// <param name="context">BaseControlContext from ASP.NET.</param> /// <returns>true if the user is signing up a tenant, otherwise, false.</returns> internal static bool IsSigningUp(this BaseControlContext context) { Guard.ArgumentNotNull(context, nameof(context)); string signupValue; // Check the HTTP context and convert to string if ((context.Ticket == null) || (!context.Ticket.Properties.Items.TryGetValue("signup", out signupValue))) { return(false); } // We have found the value, so see if it's valid bool isSigningUp; if (!bool.TryParse(signupValue, out isSigningUp)) { // The value for signup is not a valid boolean, throw throw new InvalidOperationException($"'{signupValue}' is an invalid boolean value"); } return(isSigningUp); }