public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return new AuthenticatedClient("facebook")
            {
                AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Male,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Sturm Brightblade",
                    Picture = "http://i.imgur.com/jtoOF.jpg",
                    UserName = "******"
                }
            };
        }
コード例 #2
0
        public Uri RedirectToAuthenticationProvider(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (string.IsNullOrEmpty(authenticationServiceSettings.ProviderName))
            {
                throw new ArgumentException("authenticationServiceSettings.providerName");
            }

            if (authenticationServiceSettings.CallBackUri == null ||
                string.IsNullOrEmpty(authenticationServiceSettings.CallBackUri.AbsoluteUri))
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            var authenticationProvider = GetAuthenticationProvider(authenticationServiceSettings.ProviderName);

            if (authenticationProvider == null)
            {
                throw new InvalidOperationException("No Provider found for the Provider Name: " +
                                                    authenticationServiceSettings.ProviderName);
            }

            return(authenticationProvider.RedirectToAuthenticate(authenticationServiceSettings));
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return new AuthenticatedClient("google")
            {
                AccessToken = "SomethingWonderfulHasHappened.AniImPregnant",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Female,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Natalie Portman",
                    Picture = "http://i.imgur.com/B9es0.jpg",
                    UserName = "******"
                }
            };
        }
コード例 #4
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var uriEncoded = Uri.EscapeUriString(authenticationServiceSettings.CallBackUri.AbsoluteUri);

            var oauthDialogUri =
                string.Format(
                    "https://www.amazon.com/ap/oa?client_id={0}&scope=profile&redirect_uri={1}&response_type=code{2}",
                    _clientId, uriEncoded, state);

            return(new Uri(oauthDialogUri));
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return new AuthenticatedClient("facebook")
            {
                AccessToken = "IAmALittleTeaPotShortAndStout",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Female,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Leah Culver",
                    Picture = "http://i.imgur.com/f4mIx.png",
                    UserName = "******"
                }
            };
        }
コード例 #6
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);


            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(oAuthAccessToken.ExpiresIn),
                UserInformation = new UserInformation
                {
                    Id = userInfo.Id,
                    Name = userInfo.FirstName + " " + userInfo.LastName,
                    Email = userInfo.EmailAddress,
                }
            });
        }
コード例 #7
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);

            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                UserInformation = new UserInformation
                {
                    Id = userInfo.Profile.CustomerId,
                    Name = userInfo.Profile.Name,
                    Email = userInfo.Profile.PrimaryEmail
                }
            });
        }
コード例 #8
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // Do we have any scope options?
            // NOTE: LinkedIn uses a space-delimeted string for their scope key.
            var scope = (_scope != null && _scope.Count > 0)
                            ? string.Format(ScopeKey, string.Join("%20", _scope))
                            : string.Empty;

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var oauthDialogUri =
                string.Format(
                    "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id={0}&redirect_uri={1}{2}{3}",
                    _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, state, scope);

            return(new Uri(oauthDialogUri));
        }
コード例 #9
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return(new AuthenticatedClient("facebook")
            {
                AccessToken = "IAmALittleTeaPotShortAndStout",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Female,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Leah Culver",
                    Picture = "http://i.imgur.com/f4mIx.png",
                    UserName = "******"
                }
            });
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return(new AuthenticatedClient("google")
            {
                AccessToken = "SomethingWonderfulHasHappened.AniImPregnant",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Female,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Natalie Portman",
                    Picture = "http://i.imgur.com/B9es0.jpg",
                    UserName = "******"
                }
            });
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (!string.IsNullOrEmpty(AuthenticateClientExceptionMessage))
            {
                throw new AuthenticationException(AuthenticateClientExceptionMessage);
            }

            return(new AuthenticatedClient("facebook")
            {
                AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
                AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
                UserInformation = UserInformation ?? new UserInformation
                {
                    Gender = GenderType.Male,
                    Id = "FakeId-" + Guid.NewGuid().ToString(),
                    Locale = "en-au",
                    Name = "Sturm Brightblade",
                    Picture = "http://i.imgur.com/jtoOF.jpg",
                    UserName = "******"
                }
            });
        }
コード例 #12
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // Retrieve the OAuth Verifier.
            var oAuthVerifier = RetrieveOAuthVerifier(queryStringParameters);

            // Convert the Request Token to an Access Token, now that we have a verifier.
            var oAuthAccessToken = RetrieveAccessToken(oAuthVerifier);

            // Grab the user information.
            var verifyCredentialsResult = VerifyCredentials(oAuthAccessToken);

            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                UserInformation = new UserInformation
                {
                    Name = verifyCredentialsResult.Name,
                    Id = verifyCredentialsResult.Id.ToString(),
                    Locale = verifyCredentialsResult.Lang,
                    UserName = verifyCredentialsResult.ScreenName,
                    Picture = verifyCredentialsResult.ProfileImageUrl
                },
                AccessToken = oAuthAccessToken.AccessToken
            });

            return(null);
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            CallBackUri = authenticationServiceSettings.CallBackUri;

            var oauthDialogUri = string.Format(RedirectUrl, _clientId, CallBackUri, _scope);

            return new Uri(oauthDialogUri);
        }
コード例 #14
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (!string.IsNullOrEmpty(RedirectToAuthenticateExceptionMessage))
            {
                throw new AuthenticationException(RedirectToAuthenticateExceptionMessage);
            }

            return _redirectToAuthenticateUri ?? new Uri("http://bit.ly/RD3lQT");
        }
コード例 #15
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (!string.IsNullOrEmpty(RedirectToAuthenticateExceptionMessage))
            {
                throw new AuthenticationException(RedirectToAuthenticateExceptionMessage);
            }

            return _redirectToAuthenticateUri ?? new Uri("http://some.fake.uri/with/lots/of/pewpew");
        }
コード例 #16
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (!string.IsNullOrEmpty(RedirectToAuthenticateExceptionMessage))
            {
                throw new AuthenticationException(RedirectToAuthenticateExceptionMessage);
            }

            return _redirectToAuthenticateUri ?? new Uri("bitly.com/Ttw62r");
        }
コード例 #17
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            var oauthDialogUri = string.Format(RedirectUrl, _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, _scope);

            oauthDialogUri += string.IsNullOrEmpty(authenticationServiceSettings.State)
                                  ? string.Empty
                                  : "&state=" + authenticationServiceSettings.State;

            return new Uri(oauthDialogUri);
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            var oauthDialogUri = string.Format(RedirectUrl, _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, _scope);

            oauthDialogUri += string.IsNullOrEmpty(authenticationServiceSettings.State)
                                  ? string.Empty
                                  : "&state=" + authenticationServiceSettings.State;

            return(new Uri(oauthDialogUri));
        }
コード例 #19
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            /*
             *  Sample Query String results - Failure
             * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             *  providerkey:openid
             *  openid.mode:cancel
             *  openid.ns:http://specs.openid.net/auth/2.0
             *
             * Sample Query String results - Success
             * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             *  providerkey:openid
             *  openid.assoc_handle:{HMAC-SHA1}{511b67b9}{DpzYWQ==}
             *  openid.claimed_id:http://username.myopenid.com/
             *  openid.identity:http://username.myopenid.com/
             *  openid.mode:id_res
             *  openid.ns:http://specs.openid.net/auth/2.0
             *  openid.ns.sreg:http://openid.net/extensions/sreg/1.1
             *  openid.op_endpoint:http://www.myopenid.com/server
             *  openid.response_nonce:2013-02-13T10:15:21ZhAJdyG
             *  openid.return_to:http://localhost:7000/authentication/authenticatecallback?providerkey=openid
             *  openid.sig:1+pvowBKpRFQFoxIVx7KDGDsGSg=
             *  openid.signed:assoc_handle,claimed_id,identity,mode,ns,ns.sreg,op_endpoint,response_nonce,return_to,signed,sreg.country,sreg.email,sreg.fullname,sreg.gender,sreg.language
             *  openid.sreg.email:[email protected]
             *  openid.sreg.fullname:FirstName Surname
             *  openid.sreg.gender:F
             *  openid.sreg.language:EN
             */
            if (queryStringParameters == null ||
                !queryStringParameters.AllKeys.Any(x => x.StartsWith("openid.")))
            {
                throw new ArgumentException("No openid.XXX Query String paramters found.");
            }

            // Check if this is a cancel.
            var mode = queryStringParameters.AllKeys.SingleOrDefault(x => x == "openid.mode");

            if (string.IsNullOrEmpty(mode) || queryStringParameters[mode] == "cancel")
            {
                throw new AuthenticationException(
                          "OpenId provider returned a Cancel state. No user information was (therefore) provided.");
            }

            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                UserInformation = RetrieveMe(queryStringParameters)
            });
        }
コード例 #20
0
        public IAuthenticatedClient GetAuthenticatedClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                           dynamic requestParameters)
        {
            var querystringParameters = new NameValueCollection();

            foreach (var item in requestParameters)
            {
                querystringParameters.Add(item, requestParameters[item]);
            }

            return(GetAuthenticatedClient(authenticationServiceSettings, querystringParameters));
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return _redirectToAuthenticateUri ?? new Uri("http://bit.ly/RD3lQT");
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return(_redirectToAuthenticateUri ?? new Uri("bitly.com/Ttw62r"));
        }
コード例 #23
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return(_redirectToAuthenticateUri ?? new Uri("http://some.fake.uri/with/lots/of/pewpew"));
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return _redirectToAuthenticateUri ?? new Uri("http://some.fake.uri/with/lots/of/pewpew");
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return _redirectToAuthenticateUri ?? new Uri("bitly.com/Ttw62r");
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            return(_redirectToAuthenticateUri ?? new Uri("http://a.fake.amazon/uri"));
        }
 public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                NameValueCollection queryStringParameters)
 {
     return new AuthenticatedClient("amazon")
     {
         AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
         AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
         UserInformation = UserInformation ?? new UserInformation
         {
             Id = "FakeId-" + Guid.NewGuid().ToString(),
             Name = "Sturm Brightblade",
             Email = "*****@*****.**"
         }
     };
 }
 public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                NameValueCollection queryStringParameters)
 {
     return(new AuthenticatedClient("amazon")
     {
         AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
         AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
         UserInformation = UserInformation ?? new UserInformation
         {
             Id = "FakeId-" + Guid.NewGuid().ToString(),
             Name = "Sturm Brightblade",
             Email = "*****@*****.**"
         }
     });
 }
コード例 #29
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            CallBackUri = authenticationServiceSettings.CallBackUri;

            return _redirectToAuthenticateUri ?? new Uri("http://a.fake.git.hub/uri");
        }
コード例 #30
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            var settings = authenticationServiceSettings as IOpenIdAuthenticationServiceSettings;

            if (settings == null)
            {
                throw new ArgumentException("authenticationServiceSettings is null or not of type IOpenIdAuthenticationServiceSettings", "authenticationServiceSettings");
            }

            // First we need to do a YADIS Discover, so we can get the real endpoint.
            var xrdsEndPoint = YadisDiscoverXrdsEndPoint(settings.Identifier);

            if (xrdsEndPoint == null || string.IsNullOrEmpty(xrdsEndPoint.AbsoluteUri))
            {
                // We don't know where to go :(
                return(null);
            }

            // If we have an endpoint, lets query that!
            var openIdEndPoint = YadisDiscoverOpenIdEndPoint(xrdsEndPoint);

            if (openIdEndPoint == null)
            {
                return(null);
            }

            var callbackUri = UrlEncode(string.Format("{0}&state={1}",
                                                      authenticationServiceSettings.CallBackUri.AbsoluteUri,
                                                      authenticationServiceSettings.State));
            var urlParts = new[]
            {
                "openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select",
                "openid.identity=http://specs.openid.net/auth/2.0/identifier_select",
                "openid.mode=checkid_setup",
                "openid.ns=http://specs.openid.net/auth/2.0",
                "openid.ns.sreg=http://openid.net/extensions/sreg/1.1",
                "openid.sreg.required=nickname",
                "openid.sreg.optional=email,fullname,gender,language",
                "no_ssl=true",
                "openid.return_to=" + callbackUri,
                "openid.realm=" + callbackUri
            };

            var url = string.Concat(openIdEndPoint.AbsoluteUri, "?", string.Join("&", urlParts));

            return(new Uri(url));
        }
 public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                NameValueCollection queryStringParameters)
 {
     return(new AuthenticatedClient("github")
     {
         AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
         AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
         UserInformation = UserInformation ?? new UserInformation
         {
             Gender = GenderType.Male,
             Id = "FakeId-" + Guid.NewGuid().ToString(),
             Locale = "en-au",
             Name = "Sturm Brightblade",
             Picture = "http://i.imgur.com/jtoOF.jpg",
             UserName = "******"
         }
     });
 }
 public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                NameValueCollection queryStringParameters)
 {
     return new AuthenticatedClient("github")
     {
         AccessToken = "EstSularusOthMithas-MyHonorIsMyLife",
         AccessTokenExpiresOn = DateTime.UtcNow.AddDays(30),
         UserInformation = UserInformation ?? new UserInformation
         {
             Gender = GenderType.Male,
             Id = "FakeId-" + Guid.NewGuid().ToString(),
             Locale = "en-au",
             Name = "Sturm Brightblade",
             Picture = "http://i.imgur.com/jtoOF.jpg",
             UserName = "******"
         }
     };
 }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            var settings = authenticationServiceSettings as IOpenIdAuthenticationServiceSettings;

            if (settings == null)
            {
                throw new ArgumentException("authenticationServiceSettings is null or not of type IOpenIdAuthenticationServiceSettings", "authenticationServiceSettings");
            }

            // First we need to do a YADIS Discover, so we can get the real endpoint.
            var xrdsEndPoint = YadisDiscoverXrdsEndPoint(settings.Identifier);

            if (xrdsEndPoint == null || string.IsNullOrEmpty(xrdsEndPoint.AbsoluteUri))
            {
                // We don't know where to go :(
                return null;
            }

            // If we have an endpoint, lets query that!
            var openIdEndPoint = YadisDiscoverOpenIdEndPoint(xrdsEndPoint);

            if (openIdEndPoint == null)
            {
                return null;
            }

            var urlParts = new[]
            {
                "openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select",
                "openid.identity=http://specs.openid.net/auth/2.0/identifier_select",
                "openid.mode=checkid_setup",
                "openid.ns=http://specs.openid.net/auth/2.0",
                "openid.ns.sreg=http://openid.net/extensions/sreg/1.1",
                "openid.sreg.required=nickname",
                "openid.sreg.optional=email,fullname,gender,language",
                "no_ssl=true",
                "openid.return_to=" + authenticationServiceSettings.CallBackUri.AbsoluteUri,
                "openid.realm=" + authenticationServiceSettings.CallBackUri.AbsoluteUri
            };

            var url = string.Concat(openIdEndPoint.AbsoluteUri, "?", string.Join("&", urlParts));

            return new Uri(url);
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (queryStringParameters == null)
            {
                throw new ArgumentNullException("queryStringParameters");
            }

            if (queryStringParameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("queryStringParameters");
            }

            var reponse  = RetrieveToken(queryStringParameters, authenticationServiceSettings.CallBackUri);
            var userInfo = RetrieveUserInfo(reponse);

            var result = new AuthenticatedClient(Name)
            {
                AccessToken          = reponse.AccessToken,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(int.Parse(reponse.ExpiresIn)),
                UserInformation      = new UserInformation
                {
                    Name     = string.Join(" ", userInfo.first_name, userInfo.last_name),
                    Locale   = userInfo.locale,
                    UserName = userInfo.name,
                    Id       = userInfo.id,
                    Email    = userInfo.emails.Preferred,
                    Gender   =
                        (GenderType)
                        Enum.Parse(typeof(GenderType), userInfo.gender ?? "Unknown",
                                   true)
                }
            };

            return(result);
        }
コード例 #35
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            var accessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            var userInformation = RetrieveMe(accessToken);

            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = accessToken,
                AccessTokenExpiresOn = DateTime.UtcNow,
                UserInformation = userInformation
            });
        }
コード例 #36
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // First we need to grab a request token.
            var requestToken = RetrieveRequestToken(authenticationServiceSettings.CallBackUri);

            // Now redirect them to the BitBucket website to authenticate.
            var request = new RestRequest("!api/1.0/oauth/authenticate");

            request.AddParameter(OAuthTokenKey, requestToken.OAuthToken);
            var restClient = _restClientFactory.CreateRestClient(BaseUrl);

            return(restClient.BuildUri(request));
        }
コード例 #37
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var oauthDialogUri =
                string.Format(
                    "https://github.com/login/oauth/authorize?client_id={0}&scope=user:email&redirect_uri={1}&response_type=code{2}",
                    _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, state);

            return(new Uri(oauthDialogUri));
        }
コード例 #38
0
        public IAuthenticatedClient GetAuthenticatedClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                           NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (queryStringParameters == null)
            {
                throw new ArgumentNullException("queryStringParameters");
            }

            if (queryStringParameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("queryStringParameters");
            }

            // Grab the Authentication Client.
            var authenticationProvider = GetAuthenticationProvider(authenticationServiceSettings.ProviderName);

            return(authenticationProvider.AuthenticateClient(authenticationServiceSettings, queryStringParameters));
        }
コード例 #39
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // First we need to grab a request token.
            var oAuthToken = RetrieveRequestToken(authenticationServiceSettings);

            // Now we need the user to enter their name/password/accept this app @ Twitter.
            // This means we need to redirect them to the Twitter website.
            var request = new RestRequest("oauth/authenticate");

            request.AddParameter(OAuthTokenKey, oAuthToken.OAuthToken);
            var restClient = RestClientFactory.CreateRestClient(BaseUrl);

            return(restClient.BuildUri(request));
        }
コード例 #40
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);


            return(new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(oAuthAccessToken.ExpiresIn),
                UserInformation = new UserInformation
                {
                    Id = userInfo.Id,
                    Gender = string.IsNullOrEmpty(userInfo.Gender)
                        ? GenderType.Unknown
                        : GenderTypeHelpers.ToGenderType(userInfo.Gender),
                    Name = userInfo.Name,
                    Email = userInfo.Email,
                    Locale = userInfo.Locale,
                    Picture = userInfo.Picture,
                    UserName = userInfo.GivenName
                }
            });
        }
コード例 #41
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            var facebookAuthenticationSettings = authenticationServiceSettings as FacebookAuthenticationServiceSettings;

            if (facebookAuthenticationSettings == null)
            {
                throw new InvalidOperationException("AuthenticationServiceSettings instance is not of type FacebookAuthenticationServiceSettings.");
            }

            var baseUri = facebookAuthenticationSettings.IsMobile
                              ? "https://m.facebook.com"
                              : "https://www.facebook.com";
            var scope = (_scope != null && _scope.Count > 0)
                            ? "&scope=" + string.Join(",", _scope)
                            : string.Empty;
            var state = !string.IsNullOrEmpty(facebookAuthenticationSettings.State)
                            ? "&state=" + facebookAuthenticationSettings.State
                            : string.Empty;
            var display = facebookAuthenticationSettings.Display == DisplayType.Unknown
                              ? string.Empty
                              : "&display=" + facebookAuthenticationSettings.Display.ToString().ToLowerInvariant();

            // REFERENCE: https://developers.facebook.com/docs/reference/dialogs/oauth/
            // NOTE: Facebook is case-sensitive anal retentive with regards to their uri + querystring params.
            //       So ... we'll lowercase the entire biatch. Thanks, Facebook :(
            var oauthDialogUri = string.Format("{0}/dialog/oauth?client_id={1}{2}{3}{4}&redirect_uri={5}",
                                               baseUri, _clientId, state, scope, display,
                                               authenticationServiceSettings.CallBackUri.AbsoluteUri);

            return(new Uri(oauthDialogUri));
        }
コード例 #42
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);

            
            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(oAuthAccessToken.ExpiresIn),
                UserInformation = new UserInformation
                {
                    Id = userInfo.Id,
                    Gender = string.IsNullOrEmpty(userInfo.Gender) 
                        ? GenderType.Unknown 
                        : GenderTypeHelpers.ToGenderType(userInfo.Gender),
                    Name = userInfo.Name,
                    Email = userInfo.Email,
                    Locale = userInfo.Locale,
                    Picture = userInfo.Picture,
                    UserName = userInfo.GivenName
                }
            };
        }
コード例 #43
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            /*
             *  Sample Query String results - Failure
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                providerkey:openid
                openid.mode:cancel
                openid.ns:http://specs.openid.net/auth/2.0
              
               Sample Query String results - Success
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                providerkey:openid
                openid.assoc_handle:{HMAC-SHA1}{511b67b9}{DpzYWQ==}
                openid.claimed_id:http://username.myopenid.com/
                openid.identity:http://username.myopenid.com/
                openid.mode:id_res
                openid.ns:http://specs.openid.net/auth/2.0
                openid.ns.sreg:http://openid.net/extensions/sreg/1.1
                openid.op_endpoint:http://www.myopenid.com/server
                openid.response_nonce:2013-02-13T10:15:21ZhAJdyG
                openid.return_to:http://localhost:7000/authentication/authenticatecallback?providerkey=openid
                openid.sig:1+pvowBKpRFQFoxIVx7KDGDsGSg=
                openid.signed:assoc_handle,claimed_id,identity,mode,ns,ns.sreg,op_endpoint,response_nonce,return_to,signed,sreg.country,sreg.email,sreg.fullname,sreg.gender,sreg.language
                openid.sreg.email:[email protected]
                openid.sreg.fullname:FirstName Surname
                openid.sreg.gender:F
                openid.sreg.language:EN
             */
            if (queryStringParameters == null || 
                !queryStringParameters.AllKeys.Any(x => x.StartsWith("openid.")))
            {
                throw new ArgumentException("No openid.XXX Query String paramters found.");
            }

            // Check if this is a cancel.
            var mode = queryStringParameters.AllKeys.SingleOrDefault(x => x == "openid.mode");

            if (string.IsNullOrEmpty(mode) || queryStringParameters[mode] == "cancel")
            {
                throw new AuthenticationException(
                    "OpenId provider returned a Cancel state. No user information was (therefore) provided.");
            }

            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                UserInformation = RetrieveMe(queryStringParameters)
            };
        }
コード例 #44
0
        private RequestTokenResult RetrieveRequestToken(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null ||
                string.IsNullOrEmpty(authenticationServiceSettings.CallBackUri.AbsoluteUri))
            {
                throw new ArgumentException("AuthenticationServiceSettings.CallBackUri");
            }

            if (string.IsNullOrEmpty(authenticationServiceSettings.State))
            {
                throw new ArgumentException("AuthenticationServiceSettings.State");
            }

            IRestResponse response;
            var           callBackUri = string.Format("{0}&state={1}", authenticationServiceSettings.CallBackUri,
                                                      authenticationServiceSettings.State);

            try
            {
                var restClient = RestClientFactory.CreateRestClient(BaseUrl);
                restClient.Authenticator = OAuth1Authenticator.ForRequestToken(_consumerKey, _consumerSecret, callBackUri);
                var request = new RestRequest("oauth/request_token", Method.POST);
                response = restClient.Execute(request);
            }
            catch (Exception exception)
            {
                throw new AuthenticationException("Failed to obtain a Request Token from Twitter.", exception);
            }

            if (response == null ||
                response.StatusCode != HttpStatusCode.OK)
            {
                throw new AuthenticationException(
                          string.Format(
                              "Failed to obtain a Request Token from Twitter OR the the response was not an HTTP Status 200 OK. Response Status: {0}. Response Description: {1}",
                              response == null ? "-- null response --" : response.StatusCode.ToString(),
                              response == null ? string.Empty : response.StatusDescription));
            }

            // Grab the params which should have the request token info.
            var querystringParameters = HttpUtility.ParseQueryString(response.Content);
            var oAuthToken            = querystringParameters[OAuthTokenKey];
            var oAuthTokenSecret      = querystringParameters[OAuthTokenSecretKey];

            if (string.IsNullOrEmpty(oAuthToken) ||
                string.IsNullOrEmpty(oAuthTokenSecret))
            {
                throw new AuthenticationException(
                          "Retrieved a Twitter Request Token but it doesn't contain both the oauth_token and oauth_token_secret parameters.");
            }

            return(new RequestTokenResult
            {
                OAuthToken = oAuthToken,
                OAuthTokenSecret = oAuthTokenSecret
            });
        }
コード例 #45
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            var facebookAuthenticationSettings = authenticationServiceSettings as FacebookAuthenticationServiceSettings;
            if (facebookAuthenticationSettings == null)
            {
                throw new InvalidOperationException("AuthenticationServiceSettings instance is not of type FacebookAuthenticationServiceSettings.");
            }

            // Remember the callback uri.
            CallBackUri = authenticationServiceSettings.CallBackUri;

            var baseUri = facebookAuthenticationSettings.IsMobile
                              ? "https://m.facebook.com"
                              : "https://www.facebook.com";
            var scope = (_scope != null && _scope.Count > 0)
                            ? "&scope=" + string.Join(",", _scope)
                            : string.Empty;
            var state = !string.IsNullOrEmpty(facebookAuthenticationSettings.State)
                            ? "&state=" + facebookAuthenticationSettings.State
                            : string.Empty;
            var display = facebookAuthenticationSettings.Display == DisplayType.Unknown
                              ? string.Empty
                              : "&display=" + facebookAuthenticationSettings.Display.ToString().ToLowerInvariant();

            // REFERENCE: https://developers.facebook.com/docs/reference/dialogs/oauth/
            // NOTE: Facebook is case-sensitive anal retentive with regards to their uri + querystring params.
            //       So ... we'll lowercase the entire biatch. Thanks, Facebook :(
            var oauthDialogUri = string.Format("{0}/dialog/oauth?client_id={1}{2}{3}{4}&redirect_uri={5}",
                                               baseUri, _clientId, state, scope, display, CallBackUri.AbsoluteUri);

            return new Uri(oauthDialogUri);
        }
        private RequestTokenResult RetrieveRequestToken(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null ||
                string.IsNullOrEmpty(authenticationServiceSettings.CallBackUri.AbsoluteUri))
            {
                throw new ArgumentException("AuthenticationServiceSettings.CallBackUri");
            }

            if (string.IsNullOrEmpty(authenticationServiceSettings.State))
            {
                throw new ArgumentException("AuthenticationServiceSettings.State");
            }

            IRestResponse response;
            var callBackUri = string.Format("{0}&state={1}", authenticationServiceSettings.CallBackUri,
                                            authenticationServiceSettings.State);

            try
            {
                var restClient = _restClientFactory.CreateRestClient(BaseUrl);
                restClient.Authenticator = OAuth1Authenticator.ForRequestToken(_consumerKey, _consumerSecret, callBackUri);
                var request = new RestRequest("oauth/request_token", Method.POST);
                response = restClient.Execute(request);
            }
            catch (Exception exception)
            {
                throw new AuthenticationException("Failed to obtain a Request Token from Twitter.", exception);
            }

            if (response == null ||
                response.StatusCode != HttpStatusCode.OK)
            {
                throw new AuthenticationException(
                    string.Format(
                        "Failed to obtain a Request Token from Twitter OR the the response was not an HTTP Status 200 OK. Response Status: {0}. Response Description: {1}",
                        response == null ? "-- null response --" : response.StatusCode.ToString(),
                        response == null ? string.Empty : response.StatusDescription));
            }

            // Grab the params which should have the request token info.
            var querystringParameters = HttpUtility.ParseQueryString(response.Content);
            var oAuthToken = querystringParameters[OAuthTokenKey];
            var oAuthTokenSecret = querystringParameters[OAuthTokenSecretKey];

            if (string.IsNullOrEmpty(oAuthToken) ||
                string.IsNullOrEmpty(oAuthTokenSecret))
            {
                throw new AuthenticationException(
                    "Retrieved a Twitter Request Token but it doesn't contain both the oauth_token and oauth_token_secret parameters.");
            }

            return new RequestTokenResult
            {
                OAuthToken = oAuthToken,
                OAuthTokenSecret = oAuthTokenSecret
            };
        }
コード例 #47
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // Remember the callback uri.
            CallBackUri = authenticationServiceSettings.CallBackUri;

            // Do we have any scope options?
            // NOTE: Google uses a space-delimeted string for their scope key.
            var scope = (_scope != null && _scope.Count > 0)
                            ? string.Format(ScopeKey, string.Join(" ", _scope))
                            : string.Empty;

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var oauthDialogUri =
                string.Format(
                    "https://accounts.google.com/o/oauth2/auth?client_id={0}&redirect_uri={1}&response_type=code{2}{3}",
                    _clientId, CallBackUri.AbsoluteUri, state, scope);

            return new Uri(oauthDialogUri);
        }
コード例 #48
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // Retrieve the OAuth Verifier.
            var oAuthVerifier = RetrieveOAuthVerifier(queryStringParameters);
            
            // Convert the Request Token to an Access Token, now that we have a verifier.
            var oAuthAccessToken = RetrieveAccessToken(oAuthVerifier);

            // Grab the user information.
            var verifyCredentialsResult = VerifyCredentials(oAuthAccessToken);

            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                UserInformation = new UserInformation
                {
                    Name = verifyCredentialsResult.Name,
                    Id = verifyCredentialsResult.Id.ToString(),
                    Locale = verifyCredentialsResult.Lang,
                    UserName = verifyCredentialsResult.ScreenName,
                    Picture = verifyCredentialsResult.ProfileImageUrl
                },
                AccessToken = oAuthAccessToken.AccessToken
            };

            return null;
        }
コード例 #49
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // Do we have any scope options?
            // NOTE: LinkedIn uses a space-delimeted string for their scope key.
            var scope = (_scope != null && _scope.Count > 0)
                            ? string.Format(ScopeKey, string.Join("%20", _scope))
                            : string.Empty;

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var oauthDialogUri =
                string.Format(
                    "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id={0}&redirect_uri={1}{2}{3}",
                    _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, state, scope);

            return new Uri(oauthDialogUri);
        }
コード例 #50
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                        NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (queryStringParameters == null)
            {
                throw new ArgumentNullException("queryStringParameters");
            }

            if (queryStringParameters.Count <= 0)
            {
                throw new ArgumentOutOfRangeException("queryStringParameters");
            }

            var state = queryStringParameters["state"];

            // CSRF (state) check.
            // NOTE: There is always a state provided. Even if an error is returned.
            if (!string.IsNullOrEmpty(state) && state != authenticationServiceSettings.State)
            {
                throw new AuthenticationException("The states do not match. It's possible that you may be a victim of a CSRF.");
            }

            var reponse = RetrieveToken(queryStringParameters, authenticationServiceSettings.CallBackUri);
            var userInfo = RetrieveUserInfo(reponse);

            var result = new AuthenticatedClient(Name)
                         {
                             AccessToken = reponse.access_token,
                             AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(int.Parse(reponse.expires_in)),
                             UserInformation = new UserInformation
                                               {
                                                   Name = string.Join(" ", userInfo.first_name, userInfo.last_name),
                                                   Locale = userInfo.locale,
                                                   UserName = userInfo.name,
                                                   Id = userInfo.id,
                                                   Email = userInfo.emails.Preferred,
                                                   Gender =
                                                       (GenderType)
                                                       Enum.Parse(typeof (GenderType), userInfo.gender ?? "Unknown",
                                                                  true)
                                               }
                         };

            return result;
        }
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);

            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                UserInformation = new UserInformation
                {
                    Id = userInfo.Id.ToString(),
                    Name = userInfo.Name,
                    Email = userInfo.Email??"",
                    Picture = userInfo.AvatarUrl,
                    UserName = userInfo.Login,
                }
            };
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            var state = string.IsNullOrEmpty(authenticationServiceSettings.State)
                            ? string.Empty
                            : "&state=" + authenticationServiceSettings.State;

            var oauthDialogUri =
                string.Format(
                    "https://github.com/login/oauth/authorize?client_id={0}&scope=email&redirect_uri={1}&response_type=code{2}",
                    _clientId, authenticationServiceSettings.CallBackUri.AbsoluteUri, state);

            return new Uri(oauthDialogUri);
        }
コード例 #53
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            var accessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            var userInformation = RetrieveMe(accessToken);

            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = accessToken,
                AccessTokenExpiresOn = DateTime.UtcNow,
                UserInformation = userInformation
            };
        }
コード例 #54
0
        public IAuthenticatedClient AuthenticateClient(IAuthenticationServiceSettings authenticationServiceSettings,
                                                       NameValueCollection queryStringParameters)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            // First up - an authorization token.
            var authorizationCode = RetrieveAuthorizationCode(queryStringParameters, authenticationServiceSettings.State);

            // Get an Access Token.
            var oAuthAccessToken = RetrieveAccessToken(authorizationCode, authenticationServiceSettings.CallBackUri);

            // Grab the user information.
            var userInfo = RetrieveUserInfo(oAuthAccessToken.AccessToken);

            
            return new AuthenticatedClient(Name.ToLowerInvariant())
            {
                AccessToken = oAuthAccessToken.AccessToken,
                AccessTokenExpiresOn = DateTime.UtcNow.AddSeconds(oAuthAccessToken.ExpiresIn),
                UserInformation = new UserInformation
                {
                    Id = userInfo.Id,
                    Name = userInfo.FirstName + " " + userInfo.LastName,
                    Email = userInfo.EmailAddress,
                }
            };
        }
コード例 #55
0
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // First we need to grab a request token.
            var requestToken = RetrieveRequestToken(authenticationServiceSettings.CallBackUri);

            // Now redirect them to the BitBucket website to authenticate.
            var request = new RestRequest("!api/1.0/oauth/authenticate");
            request.AddParameter(OAuthTokenKey, requestToken.OAuthToken);
            var restClient = _restClientFactory.CreateRestClient(BaseUrl);
            return restClient.BuildUri(request);
        }
        public Uri RedirectToAuthenticate(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (authenticationServiceSettings.CallBackUri == null)
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            // First we need to grab a request token.
            var oAuthToken = RetrieveRequestToken(authenticationServiceSettings);

            // Now we need the user to enter their name/password/accept this app @ Twitter.
            // This means we need to redirect them to the Twitter website.
            var request = new RestRequest("oauth/authenticate");
            request.AddParameter(OAuthTokenKey, oAuthToken.OAuthToken);
            var restClient = _restClientFactory.CreateRestClient(BaseUrl);
            return restClient.BuildUri(request);
        }
        public Uri RedirectToAuthenticationProvider(IAuthenticationServiceSettings authenticationServiceSettings)
        {
            if (authenticationServiceSettings == null)
            {
                throw new ArgumentNullException("authenticationServiceSettings");
            }

            if (string.IsNullOrEmpty(authenticationServiceSettings.ProviderName))
            {
                throw new ArgumentException("authenticationServiceSettings.providerName");
            }

            if (authenticationServiceSettings.CallBackUri == null ||
                string.IsNullOrEmpty(authenticationServiceSettings.CallBackUri.AbsoluteUri))
            {
                throw new ArgumentException("authenticationServiceSettings.CallBackUri");
            }

            var authenticationProvider = GetAuthenticationProvider(authenticationServiceSettings.ProviderName);

            return authenticationProvider.RedirectToAuthenticate(authenticationServiceSettings);
        }