Пример #1
0
 public OAuth2ActionResult(OAuth2Client client, string type, string returnUrl)
 {
     this.client    = client;
     this.type      = type;
     this.returnUrl = returnUrl;
 }
        private ActionResult RedirectToOAuth2IdentityProvider(IdentityProvider ip, SignInRequestMessage request)
        {
            var ctx = new OAuth2Context
            {
                Wctx = request.Context,
                Realm = request.Realm,
                IdP = ip.ID
            };

            SetOAuthContextCookie(ctx);

            var oauth2 = new OAuth2Client(GetProviderTypeFromOAuthProfileTypes(ip.ProviderType.Value), ip.ClientID, ip.ClientSecret);
            switch (ip.ProviderType)
            {
                case OAuth2ProviderTypes.Google:
                    return new OAuth2ActionResult(oauth2, ProviderType.Google, null);
                case OAuth2ProviderTypes.Facebook:
                    return new OAuth2ActionResult(oauth2, ProviderType.Facebook, null);
                case OAuth2ProviderTypes.Live:
                    return new OAuth2ActionResult(oauth2, ProviderType.Live, null);
                case OAuth2ProviderTypes.LinkedIn:
                    return new OAuth2ActionResult(oauth2, ProviderType.LinkedIn, null);
            }

            return View("Error");
        }
 public OAuth2ActionResult(OAuth2Client client, ProviderType type, string returnUrl)
 {
     this.client = client;
     this.type = type;
     this.returnUrl = returnUrl;
 }
        public async Task<ActionResult> OAuthTokenCallback()
        {
            var ctx = GetOAuthContextCookie();
            var ip = GetEnabledOAuthIdentityProviders().Single(x => x.ID == ctx.IdP);

            var oauth2 = new OAuth2Client(GetProviderTypeFromOAuthProfileTypes(ip.ProviderType.Value), ip.ClientID, ip.ClientSecret);
            var result = await oauth2.ProcessCallbackAsync();
            if (result.Error != null) return View("Error");

            var claims = result.Claims.ToList();
            claims.Add(new Claim(Constants.Claims.IdentityProvider, ip.Name, ClaimValueTypes.String, Constants.InternalIssuer));
            var id = new ClaimsIdentity(claims, "OAuth");
            var cp = new ClaimsPrincipal(id);

            return ProcessOAuthResponse(cp, ctx);
        }
        public async Task<ActionResult> OAuthTokenCallback()
        {
            var ctx = GetOAuthContextCookie();
            var ip = GetEnabledOAuthIdentityProviders().Single(x => x.ID == ctx.IdP);

            var oauth2 = new OAuth2Client(GetProviderTypeFromOAuthProfileTypes(ip.ProviderType.Value), ip.ClientID, ip.ClientSecret);
            var result = await oauth2.ProcessCallbackAsync();
            if (result.Error != null) return View("Error");

            var claims = result.Claims.ToList();
            string[] claimsToRemove = new string[]
            {
                "http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider",
                ClaimTypes.AuthenticationInstant
            };
            
            foreach (var toRemove in claimsToRemove)
            {
                var tmp = claims.Find(x => x.Type == toRemove);
                if (tmp != null) claims.Remove(tmp);
            }
            
            claims.Add(new Claim(Constants.Claims.IdentityProvider, ip.Name, ClaimValueTypes.String, Constants.InternalIssuer));
            var id = new ClaimsIdentity(claims, "OAuth");
            var cp = new ClaimsPrincipal(id);
            
            return ProcessOAuthResponse(cp, ctx);
        }