当前位置: 首页>>代码示例>>C#>>正文


C# IAuthenticationResponse类代码示例

本文整理汇总了C#中IAuthenticationResponse的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticationResponse类的具体用法?C# IAuthenticationResponse怎么用?C# IAuthenticationResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IAuthenticationResponse类属于命名空间,在下文中一共展示了IAuthenticationResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessUserAuthorizationAsync

		/// <summary>
		/// Processes an incoming authorization-granted message from an SP and obtains an access token.
		/// </summary>
		/// <param name="openIdAuthenticationResponse">The OpenID authentication response that may be carrying an authorized request token.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <returns>
		/// The access token, or null if OAuth authorization was denied by the user or service provider.
		/// </returns>
		/// <remarks>
		/// The access token, if granted, is automatically stored in the <see cref="ConsumerBase.TokenManager" />.
		/// The token manager instance must implement <see cref="IOpenIdOAuthTokenManager" />.
		/// </remarks>
		public async Task<AccessTokenResponse> ProcessUserAuthorizationAsync(IAuthenticationResponse openIdAuthenticationResponse, CancellationToken cancellationToken = default(CancellationToken)) {
			Requires.NotNull(openIdAuthenticationResponse, "openIdAuthenticationResponse");

			// The OAuth extension is only expected in positive assertion responses.
			if (openIdAuthenticationResponse.Status != AuthenticationStatus.Authenticated) {
				return null;
			}

			// Retrieve the OAuth extension
			var positiveAuthorization = openIdAuthenticationResponse.GetExtension<AuthorizationApprovedResponse>();
			if (positiveAuthorization == null) {
				return null;
			}

			using (var client = this.CreateHttpClient(new AccessToken(positiveAuthorization.RequestToken, string.Empty))) {
				var request = new HttpRequestMessage(this.ServiceProvider.TokenRequestEndpointMethod, this.ServiceProvider.TokenRequestEndpoint);
				using (var response = await client.SendAsync(request, cancellationToken)) {
					response.EnsureSuccessStatusCode();

					// Parse the response and ensure that it meets the requirements of the OAuth 1.0 spec.
					string content = await response.Content.ReadAsStringAsync();
					var responseData = HttpUtility.ParseQueryString(content);
					string accessToken = responseData[Protocol.TokenParameter];
					string tokenSecret = responseData[Protocol.TokenSecretParameter];
					ErrorUtilities.VerifyProtocol(!string.IsNullOrEmpty(accessToken), MessagingStrings.RequiredParametersMissing, typeof(AuthorizedTokenResponse).Name, Protocol.TokenParameter);
					ErrorUtilities.VerifyProtocol(tokenSecret != null, MessagingStrings.RequiredParametersMissing, typeof(AuthorizedTokenResponse).Name, Protocol.TokenSecretParameter);

					responseData.Remove(Protocol.TokenParameter);
					responseData.Remove(Protocol.TokenSecretParameter);
					return new AccessTokenResponse(accessToken, tokenSecret, responseData);
				}
			}
		}
开发者ID:Adilson,项目名称:dotnetopenid,代码行数:45,代码来源:WebConsumerOpenIdRelyingParty.cs

示例2: SetUserInformationGeneric

 private void SetUserInformationGeneric(IAuthenticationResponse response)
 {
     var userdata = response.GetExtension<ClaimsResponse>();
     var email = userdata.Email;
     FullName = userdata.FullName;
     Email = email;
 }
开发者ID:phoenixwebgroup,项目名称:Accountability,代码行数:7,代码来源:UserInformation.cs

示例3: ProcessUserAuthorization

		/// <summary>
		/// Processes an incoming authorization-granted message from an SP and obtains an access token.
		/// </summary>
		/// <param name="openIdAuthenticationResponse">The OpenID authentication response that may be carrying an authorized request token.</param>
		/// <returns>
		/// The access token, or null if OAuth authorization was denied by the user or service provider.
		/// </returns>
		/// <remarks>
		/// The access token, if granted, is automatically stored in the <see cref="ConsumerBase.TokenManager"/>.
		/// The token manager instance must implement <see cref="IOpenIdOAuthTokenManager"/>.
		/// </remarks>
		public AuthorizedTokenResponse ProcessUserAuthorization(IAuthenticationResponse openIdAuthenticationResponse) {
			Requires.NotNull(openIdAuthenticationResponse, "openIdAuthenticationResponse");
			Requires.ValidState(this.TokenManager is IOpenIdOAuthTokenManager);
			var openidTokenManager = this.TokenManager as IOpenIdOAuthTokenManager;
			ErrorUtilities.VerifyOperation(openidTokenManager != null, OAuthStrings.OpenIdOAuthExtensionRequiresSpecialTokenManagerInterface, typeof(IOpenIdOAuthTokenManager).FullName);

			// The OAuth extension is only expected in positive assertion responses.
			if (openIdAuthenticationResponse.Status != AuthenticationStatus.Authenticated) {
				return null;
			}

			// Retrieve the OAuth extension
			var positiveAuthorization = openIdAuthenticationResponse.GetExtension<AuthorizationApprovedResponse>();
			if (positiveAuthorization == null) {
				return null;
			}

			// Prepare a message to exchange the request token for an access token.
			// We are careful to use a v1.0 message version so that the oauth_verifier is not required.
			var requestAccess = new AuthorizedTokenRequest(this.ServiceProvider.AccessTokenEndpoint, Protocol.V10.Version) {
				RequestToken = positiveAuthorization.RequestToken,
				ConsumerKey = this.ConsumerKey,
			};

			// Retrieve the access token and store it in the token manager.
			openidTokenManager.StoreOpenIdAuthorizedRequestToken(this.ConsumerKey, positiveAuthorization);
			var grantAccess = this.Channel.Request<AuthorizedTokenResponse>(requestAccess);
			this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, positiveAuthorization.RequestToken, grantAccess.AccessToken, grantAccess.TokenSecret);

			// Provide the caller with the access token so it may be associated with the user
			// that is logging in.
			return grantAccess;
		}
开发者ID:437072341,项目名称:dotnetopenid,代码行数:44,代码来源:WebConsumerOpenIdRelyingParty.cs

示例4: SetCommenterValuesFromOpenIdResponse

        private static void SetCommenterValuesFromOpenIdResponse(IAuthenticationResponse response, Commenter commenter)
        {
            var claimsResponse = response.GetExtension<ClaimsResponse>();
            if (claimsResponse != null)
            {
                if (string.IsNullOrWhiteSpace(commenter.Name) && string.IsNullOrWhiteSpace(claimsResponse.Nickname) == false)
                    commenter.Name = claimsResponse.Nickname;
                else if (string.IsNullOrWhiteSpace(commenter.Name) && string.IsNullOrWhiteSpace(claimsResponse.FullName) == false)
                    commenter.Name = claimsResponse.FullName;
                if (string.IsNullOrWhiteSpace(commenter.Email) && string.IsNullOrWhiteSpace(claimsResponse.Email) == false)
                    commenter.Email = claimsResponse.Email;
            }
            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null) // let us try from the attributes
            {
                if (string.IsNullOrWhiteSpace(commenter.Email))
                    commenter.Email = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email);
                if (string.IsNullOrWhiteSpace(commenter.Name))
                {
                    commenter.Name = fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName) ??
                                     fetchResponse.GetAttributeValue(WellKnownAttributes.Name.First) + " " +
                                     fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Last);
                }

                if (string.IsNullOrWhiteSpace(commenter.Url))
                {
                    commenter.Url = fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Web.Blog) ??
                                fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Web.Homepage);
                }
            }
        }
开发者ID:TimmyBoy,项目名称:RaccoonBlog,代码行数:31,代码来源:SocialLoginController.cs

示例5: GetUserClaim

        public virtual UserClaim GetUserClaim(IAuthenticationResponse response)
        {
            if (response == null) return null;

            switch (response.Status) {
                case AuthenticationStatus.Authenticated:
                    var claimsResponse = response.GetExtension<ClaimsResponse>();

                    if (claimsResponse != null) {
                        return new UserClaim {
                            Username = claimsResponse.Nickname,
                            Email = claimsResponse.Email,
                            Name = claimsResponse.FullName,
                            Identifier = response.FriendlyIdentifierForDisplay
                        };
                    }

                    return null;
                case AuthenticationStatus.Canceled:
                case AuthenticationStatus.Failed:
                    return null;
            }

            return null;
        }
开发者ID:lozanotek,项目名称:SimpleID,代码行数:25,代码来源:RelyPartyService.cs

示例6: SetUserInformationFromGoogle

 private void SetUserInformationFromGoogle(IAuthenticationResponse response)
 {
     var userdata = response.GetExtension<FetchResponse>();
     var firstname = userdata.GetAttributeValue(WellKnownAttributes.Name.First);
     var lastname = userdata.GetAttributeValue(WellKnownAttributes.Name.Last);
     FullName = firstname + " " + lastname;
     Email = userdata.GetAttributeValue(WellKnownAttributes.Contact.Email);
 }
开发者ID:phoenixwebgroup,项目名称:Accountability,代码行数:8,代码来源:UserInformation.cs

示例7: HandleUnknownUser

 protected override string HandleUnknownUser(IAuthenticationResponse response)
 {
     string username = response.ClaimedIdentifier.ToString();
     string email = response.ClaimedIdentifier.ToString();
     string comment = null;
     var sreg = response.GetExtension<DotNetOpenAuth.OpenId.Extensions.SimpleRegistration.ClaimsResponse>();
     if (sreg != null)
     {
         if (sreg.Nickname != null)
         {
             comment = sreg.Nickname;
         }
         if (sreg.Email != null)
         {
             email = sreg.Email;
         }
     }
     var ax = response.GetExtension<DotNetOpenAuth.OpenId.Extensions.AttributeExchange.FetchResponse>();
     if (ax != null)
     {
         if (ax.Attributes.Contains(WellKnownAttributes.Contact.Email))
         {
             IList<string> emailAddresses = ax.Attributes[WellKnownAttributes.Contact.Email].Values;
             email = emailAddresses.Count > 0 ? emailAddresses[0] : email;
         }
         if (ax.Attributes.Contains(WellKnownAttributes.Name.Alias))
         {
             IList<string> aliasNames = ax.Attributes[WellKnownAttributes.Name.Alias].Values;
             comment = aliasNames.Count > 0 ? aliasNames[0] : comment;
         }
     }
     try
     {
         var user = Membership.CreateUser(username, Guid.NewGuid().ToString(), email);
         NHOpenIDMembershipProvider idprov = Provider as NHOpenIDMembershipProvider;
         MembershipCreateStatus status;
         idprov.AddIdToUser(user, response.ClaimedIdentifier, out status);
         if (status == MembershipCreateStatus.Success)
         {
             if (String.IsNullOrEmpty(comment)) {
               user.Comment = email;
             } else {
               user.Comment = comment;
             }
             Provider.UpdateUser(user);
             return user.UserName;
         }
         else
         {
             Provider.DeleteUser(user.UserName, true);
         }
     }
     catch (MembershipCreateUserException)
     {
         return null;
     }
     return null;
 }
开发者ID:sztupy,项目名称:shaml,代码行数:58,代码来源:OpenIDController.cs

示例8: TryGetOpenIdResponse

 public override bool TryGetOpenIdResponse(out IAuthenticationResponse openIdResponse)
 {
     openIdResponse = openIdRelyingParty.GetResponse();
     if (openIdResponse.IsNull())
     {
         return false;
     }
     return true;
 }
开发者ID:mastoj,项目名称:NBlog,代码行数:9,代码来源:AuthenticationService.cs

示例9: AuthenticationResponseShim

		/// <summary>
		/// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
		/// </summary>
		/// <param name="response">The response.</param>
		internal AuthenticationResponseShim(IAuthenticationResponse response) {
			Contract.Requires<ArgumentNullException>(response != null);

			this.response = response;
			var claimsResponse = this.response.GetExtension<ClaimsResponse>();
			if (claimsResponse != null) {
				this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
			}
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:13,代码来源:AuthenticationResponseShim.cs

示例10: AuthenticationResponseShim

		/// <summary>
		/// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
		/// </summary>
		/// <param name="response">The response.</param>
		internal AuthenticationResponseShim(IAuthenticationResponse response) {
			Requires.NotNull(response, "response");

			this.response = response;
			var claimsResponse = this.response.GetExtension<ClaimsResponse>();
			if (claimsResponse != null) {
				this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
			}
		}
开发者ID:CooPzZ,项目名称:dotnetopenid,代码行数:13,代码来源:AuthenticationResponseShim.cs

示例11: AuthenticationResponseShim

        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationResponseShim"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        internal AuthenticationResponseShim(IAuthenticationResponse response)
        {
            Contract.Requires(response != null);
            ErrorUtilities.VerifyArgumentNotNull(response, "response");

            this.response = response;
            var claimsResponse = this.response.GetExtension<ClaimsResponse>();
            if (claimsResponse != null) {
                this.ClaimsResponse = new ClaimsResponseShim(claimsResponse);
            }
        }
开发者ID:vrushalid,项目名称:dotnetopenid,代码行数:15,代码来源:AuthenticationResponseShim.cs

示例12: GetExtraData

		/// <summary>
		/// Gets the extra data obtained from the response message when authentication is successful.
		/// </summary>
		/// <param name="response">
		/// The response message. 
		/// </param>
		/// <returns>
		/// </returns>
		protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response) {
			FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
			if (fetchResponse != null) {
				var extraData = new Dictionary<string, string>();
				extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
				extraData.AddItemIfNotEmpty("fullName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.FullName));

				return extraData;
			}

			return null;
		}
开发者ID:vonbv,项目名称:dotnetopenid,代码行数:20,代码来源:YahooOpenIdClient.cs

示例13: GetExtraData

        protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
        {
            var fetchResponse = response.GetExtension<FetchResponse>();
            if (fetchResponse != null)
            {
                var extraData = new Dictionary<string, string>();
                extraData.AddItemIfNotEmpty(ClaimTypes.IsPersistent, fetchResponse.GetAttributeValue(ClaimTypes.IsPersistent));

                return extraData;
            }
            return null;
        }
开发者ID:Teleopti,项目名称:authbridge,代码行数:12,代码来源:RelativeOpenIdClient.cs

示例14: GetFriendlyOpenId

 public static string GetFriendlyOpenId(IAuthenticationResponse response, string email)
 {
     if (response.ClaimedIdentifier.ToString().Contains(WellKnownProviders.Google))
     {
         return "Google(" + email + ")";
     }
     if (response.ClaimedIdentifier.ToString().Contains(WellKnownProviders.Yahoo))
     {
         return "Yahoo(" + email + ")";
     }
     return response.FriendlyIdentifierForDisplay;
 }
开发者ID:robiboi,项目名称:blurt.ph,代码行数:12,代码来源:PostHelper.cs

示例15: GetExtraData

 protected override Dictionary<string, string> GetExtraData(IAuthenticationResponse response)
 {
     FetchResponse extension = response.GetExtension<FetchResponse>();
     if (extension != null)
     {
         Dictionary<string, string> dictionary = new Dictionary<string, string>();
         dictionary.Add("email", extension.GetAttributeValue("http://axschema.org/contact/email"));
         dictionary.Add("name", extension.GetAttributeValue("http://axschema.org/namePerson/first") + " " + extension.GetAttributeValue("http://axschema.org/namePerson/last"));
         return dictionary;
     }
     return null;
 }
开发者ID:mikalai-silivonik,项目名称:bnh,代码行数:12,代码来源:Google.cs


注:本文中的IAuthenticationResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。