Пример #1
0
        public ActionResult Login(OAuth2Model model)
        {
            var client = new AuthenticationApiClient(
                new Uri(string.Format("https://{0}", ConfigurationManager.AppSettings["auth0:Domain"])));


            var request     = this.Request;
            var redirectUri = new UriBuilder(request.Url.Scheme, request.Url.Host, this.Request.Url.IsDefaultPort ? -1 : request.Url.Port, "LoginCallback.ashx");

            var authorizeUrlBuilder = client.BuildAuthorizationUrl()
                                      .WithClient(ConfigurationManager.AppSettings["auth0:ClientId"])
                                      .WithRedirectUrl(redirectUri.ToString())
                                      .WithResponseType(AuthorizationResponseType.Code)
                                      .WithScope("openid email offline_access")
                                      .WithAudience(string.IsNullOrEmpty(model.Audience) ? ConfigurationManager.AppSettings["resourceOwnerUrl"] : model.Audience);

            if (!string.IsNullOrEmpty(model.ReturnUrl))
            {
                var state = "ru=" + HttpUtility.UrlEncode(model.ReturnUrl);
                authorizeUrlBuilder.WithState(state);
            }
            var url = authorizeUrlBuilder.Build().ToString();

            return(new RedirectResult(url));
        }
Пример #2
0
        public ActionResult Index()
        {
            var model = new OAuth2Model
            {
                Audience = ConfigurationManager.AppSettings["resourceOwnerUrl"]
            };

            ViewBag.AccessToken  = ClaimsPrincipal.Current.FindFirst("access_token")?.Value;
            ViewBag.IdToken      = ClaimsPrincipal.Current.FindFirst("id_token")?.Value;
            ViewBag.Name         = ClaimsPrincipal.Current.FindFirst("name")?.Value;
            ViewBag.RefreshToken = ClaimsPrincipal.Current.FindFirst("refresh_token")?.Value;

            return(View(model));
        }