예제 #1
0
        public ActionResult SignInPost(CustomAccountProviderSignInViewModel model)
        {
            Debug.Assert(model != null);

            if (!ModelState.IsValid)
            {
                return(CustomView(model));
            }

            var returnUrl = new Uri(model.ReturnUrl);

            if (!CustomAccountProviderManager.ValidateReturnUrl(returnUrl))
            {
                return(new HttpUnauthorizedResult());
            }

            // Do validation
            // If the user is in the process of linking his account to another account there is the account provider can be retrieved with GetLinkAccountAccountProvider())
            var accountProvider = (GetAccountProvider() as CustomAccountProvider) ?? GetLinkAccountAccountProvider() as CustomAccountProvider;

            if (accountProvider == null)
            {
                return(new HttpUnauthorizedResult());
            }

            CookieManager.SetCustomAccountProviderValueInCookie("124578895613", new Framework.Cryptography.Identifier(accountProvider.AccountProviderId));

            return(new RedirectResult(returnUrl.AbsoluteUri));
        }
예제 #2
0
        /// <summary>
        /// Gets the sign in URL.
        /// </summary>
        /// <param name="returnUrl">The return url.</param>
        /// <param name="state">The state.</param>
        /// <returns>
        /// The sign in url.
        /// </returns>
        public Task <Uri> GetSignInUrlAsync(Uri returnUrl, string state)
        {
            if (returnUrl == null)
            {
                throw new ArgumentNullException(nameof(returnUrl));
            }

            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            if (CustomAccountProviderManager.ValidateReturnUrl(returnUrl))
            {
                var tenant = CustomAccountProviderManager.GetTenantUrlSegment(HttpContext.Current.Request);

                return(Task.FromResult(
                           new Uri(
                               string.Format(
                                   CultureInfo.InvariantCulture,
                                   string.Format(CultureInfo.InvariantCulture, CustomAccountProviderManagerFactory.CustomAccountProviderLogonUrl, tenant) + "?returnUrl={0}&state={1}",
                                   returnUrl.UrlEncode(),
                                   state.Base64ToBase64Url()))));
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(returnUrl), "Invalid returnUrl");
            }
        }