/// <summary>
    ///     Used to render the script that will pass in the angular "externalLoginInfo" service/value on page load
    /// </summary>
    /// <param name="html"></param>
    /// <param name="externalLogins"></param>
    /// <returns></returns>
    public static async Task <IHtmlContent> AngularValueExternalLoginInfoScriptAsync(this IHtmlHelper html,
                                                                                     IBackOfficeExternalLoginProviders externalLogins,
                                                                                     BackOfficeExternalLoginProviderErrors externalLoginErrors)
    {
        IEnumerable <BackOfficeExternaLoginProviderScheme>
        providers = await externalLogins.GetBackOfficeProvidersAsync();

        var loginProviders = providers
                             .Select(p => new
        {
            authType   = p.ExternalLoginProvider.AuthenticationType,
            caption    = p.AuthenticationScheme.DisplayName,
            properties = p.ExternalLoginProvider.Options
        })
                             .ToArray();

        var sb = new StringBuilder();

        sb.AppendLine();
        sb.AppendLine(@"var errors = [];");

        if (externalLoginErrors != null)
        {
            if (externalLoginErrors.Errors is not null)
            {
                foreach (var error in externalLoginErrors.Errors)
                {
                    sb.AppendFormat(@"errors.push(""{0}"");", error.ToSingleLine()).AppendLine();
                }
            }
        }

        sb.AppendLine(@"app.value(""externalLoginInfo"", {");
        if (externalLoginErrors?.AuthenticationType != null)
        {
            sb.AppendLine($@"errorProvider: '{externalLoginErrors.AuthenticationType}',");
        }

        sb.AppendLine(@"errors: errors,");
        sb.Append(@"providers: ");
        sb.AppendLine(JsonConvert.SerializeObject(loginProviders));
        sb.AppendLine(@"});");

        return(html.Raw(sb.ToString()));
    }
 /// <summary>
 /// Used by the back office controller to register any external login provider errors
 /// </summary>
 /// <param name="viewData"></param>
 /// <param name="errors"></param>
 public static void SetExternalSignInProviderErrors(this ViewDataDictionary viewData, BackOfficeExternalLoginProviderErrors errors)
 {
     viewData[TokenExternalSignInError] = errors;
 }
Beispiel #3
0
 /// <summary>
 /// Used by external login providers to set any errors that occur during the OAuth negotiation
 /// </summary>
 /// <param name="owinContext"></param>
 /// <param name="errors"></param>
 public static void SetExternalLoginProviderErrors(this IOwinContext owinContext, BackOfficeExternalLoginProviderErrors errors)
 => owinContext.Set(errors);
 public static void SetExternalSignInError(this ViewDataDictionary viewData, IEnumerable <string> value)
 {
     viewData[TokenExternalSignInError] = new BackOfficeExternalLoginProviderErrors(string.Empty, value);
 }
Beispiel #5
0
        /// <summary>
        /// Used to render the script that will pass in the angular "externalLoginInfo" service/value on page load
        /// </summary>
        /// <param name="html"></param>
        /// <param name="externalLoginErrors"></param>
        /// <returns></returns>
        public static IHtmlString AngularValueExternalLoginInfoScript(this HtmlHelper html, BackOfficeExternalLoginProviderErrors externalLoginErrors)
        {
            var loginProviders = html.ViewContext.HttpContext.GetOwinContext().Authentication.GetBackOfficeExternalLoginProviders()
                                 .Select(p => new
            {
                authType   = p.AuthenticationType,
                caption    = p.Caption,
                properties = p.Properties
            })
                                 .ToArray();

            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine(@"var errors = [];");

            if (externalLoginErrors != null)
            {
                foreach (var error in externalLoginErrors.Errors)
                {
                    sb.AppendFormat(@"errors.push(""{0}"");", error.ToSingleLine()).AppendLine();
                }
            }

            sb.AppendLine(@"app.value(""externalLoginInfo"", {");
            if (externalLoginErrors?.AuthenticationType != null)
            {
                sb.AppendLine($@"errorProvider: '{externalLoginErrors.AuthenticationType}',");
            }
            sb.AppendLine(@"errors: errors,");
            sb.Append(@"providers: ");
            sb.AppendLine(JsonConvert.SerializeObject(loginProviders));
            sb.AppendLine(@"});");

            return(html.Raw(sb.ToString()));
        }
 public static void SetExternalLoginProviderErrors(this HttpContext httpContext, BackOfficeExternalLoginProviderErrors errors)
 => httpContext.Items[nameof(BackOfficeExternalLoginProviderErrors)] = errors;