コード例 #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);
        }
コード例 #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
                    }
                }
            }
        }
コード例 #3
0
 public OAuth2Client(ProviderType providerType, string clientID, string clientSecret, string scope = null)
 {
     this.RegisterProvider(providerType, clientID, clientSecret, scope);
 }
コード例 #4
0
 public OAuth2ActionResult(OAuth2Client client, ProviderType type, string returnUrl)
 {
     this.client    = client;
     this.type      = type;
     this.returnUrl = returnUrl;
 }
コード例 #5
0
 public OAuth2ActionResult(ProviderType type, string returnUrl)
     : this(OAuth2Client.Instance, type, returnUrl)
 {
 }
コード例 #6
0
 public OAuth2ActionResult(ProviderType type)
     : this(OAuth2Client.Instance, type, null)
 {
 }