Exemplo n.º 1
0
        public void RedirectToAuthorizationProvider(
            ProviderType providerType, string returnUrl = null)
        {
            var provider = this.GetProvider(providerType);

            var redirect = provider.GetRedirect();
            var authCtx  = new AuthorizationContext
            {
                ProviderType = providerType,
                ReturnUrl    = returnUrl,
                State        = redirect.State
            };

            SaveContext(authCtx);

            var ctx = HttpContext.Current;

            ctx.Response.Redirect(redirect.AuthorizationUrl);
        }
Exemplo n.º 2
0
        public override void RegisterArea(AreaRegistrationContext context)
        {
            if (OAuth2Client.AutoRegisterOAuthCallbackUrl)
            {
                context.MapRoute("OAuth2Client-CodeCallback",
                                 OAuth2Client.OAuthCallbackUrl,
                                 new { controller = "OAuth2Callback", action = "Callback" });

                var settings  = System.Web.Configuration.WebConfigurationManager.AppSettings;
                var providers = from v in
                                (from string q in settings.Keys
                                 where q.StartsWith("oauth2:")
                                 select new { key = q.Split(':'), value = settings[q] })
                                group v by v.key[1];
                foreach (var provider in providers)
                {
                    try
                    {
                        ProviderType type = provider.Key == "facebook" ? ProviderType.Facebook :
                                            provider.Key == "google" ? ProviderType.Google :
                                            ProviderType.Live;

                        var scope = provider.FirstOrDefault(k => k.key[2].ToLower() == "scope");


                        OAuth2Client.Instance.RegisterProvider(type,
                                                               provider.First(k => k.key[2].ToLower() == "clientid").value,
                                                               provider.First(k => k.key[2].ToLower() == "clientsecret").value,
                                                               scope == null || String.IsNullOrEmpty(scope.value) ?  null : scope.value);
                    } catch
                    {
                        //Not adding
                    }
                }
            }
        }
Exemplo n.º 3
0
 public OAuth2Client(ProviderType providerType, string clientID, string clientSecret, string scope = null)
 {
     this.RegisterProvider(providerType, clientID, clientSecret, scope);
 }
Exemplo n.º 4
0
 public OAuth2ActionResult(OAuth2Client client, ProviderType type, string returnUrl)
 {
     this.client    = client;
     this.type      = type;
     this.returnUrl = returnUrl;
 }
Exemplo n.º 5
0
 public OAuth2ActionResult(ProviderType type, string returnUrl)
     : this(OAuth2Client.Instance, type, returnUrl)
 {
 }
Exemplo n.º 6
0
 public OAuth2ActionResult(ProviderType type)
     : this(OAuth2Client.Instance, type, null)
 {
 }