• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IAuthenticationResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: AuthenticateUser

   /// <summary>
   /// This authenticates a user based on a response from an openid provider.
   /// </summary>
   /// <param name="response"></param>
   private void AuthenticateUser(IAuthenticationResponse response)
   {
      if (response.Status != AuthenticationStatus.Authenticated)
         throw new ArgumentException("The response status must be 'Authenticated'. (" + response.Status.ToString() + ")", "response");

      Identifier identifier = response.ClaimedIdentifier;

      if (identifier == null)
      {
         lblError.Text = "Oops! We lost the ID you tried to log in with. Can you try again?";
      }
      else
      {
         using (SqlConnection cn = new SqlConnection(Database.TadMapConnection))
         {
            cn.Open();
            using (SqlCommand cm = cn.CreateCommand())
            {
               cm.CommandType = CommandType.StoredProcedure;
               cm.CommandText = "GetUserId";
               cm.Parameters.AddWithValue("@OpenIdUrl", identifier.ToString());

               using (SqlDataReader dr = cm.ExecuteReader())
               {
                  if (dr.Read())
                  {
                     // a record was found so the user already exists
                     // in the future we can use this to populate the identity
                     // with display name and image...
                  }
                  else
                  {
                     // no user was found so we create it now.
                     CreateNewUser(identifier.ToString());
                  }
               }
            }
         }

         // somehow we need to put the response.FriendlyIdentifierForDisplay
         // into the identity/principal

         if (Request.QueryString["ReturnUrl"] != null)
         {
            FormsAuthentication.RedirectFromLoginPage(identifier.ToString(), false);
         }
         else
         {
            FormsAuthentication.SetAuthCookie(identifier.ToString(), false);
            Response.Redirect("MyImages.aspx", false);
         }
      }
   }
开发者ID:trevorpower,项目名称:tadmap,代码行数:57,代码来源:Login.aspx.cs


示例17: ProcessOpenIdResponse

        internal AuthenticationResult ProcessOpenIdResponse(IAuthenticationResponse response)
        {
            switch (response.Status)
            {
                default:
                {
                    return AbortedAuthentication(Common.Resources.Authentication.InvalidOpenAuthenticationStatus);
                }
                case AuthenticationStatus.Canceled:
                {
                    return AbortedAuthentication(Common.Resources.Authentication.CanceledAtProvider, ConnectionStatus.Canceled);
                }
                case AuthenticationStatus.Failed:
                {
                    return AuthenticationException(response.Exception);
                }
                case AuthenticationStatus.Authenticated:
                {
                    string openId = response.ClaimedIdentifier;
                    User user = userService.GetByOpenId(openId);
                    bool isNewUser = false;
                    bool isNewConnection = false;
                    if (user == null)
                    {
                        isNewConnection = true;

                        string email = null;
                        string displayName = null;
                        var fetch = response.GetExtension<FetchResponse>();
                        if (fetch != null)
                        {
                            email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
                            displayName = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);
                        }
                        if (!email.NullOrEmpty()) // maybe they already have an account.
                        {
                            user = userService.GetByEmail(email);
                        }
                        if (user == null) // create a brand new account.
                        {
                            user = userService.CreateWithOpenId(openId, email, displayName);
                            isNewUser = true;
                        }
                        else // just connect the existing account to their OpenId account.
                        {
                            userService.AddOpenIdConnection(user, openId);
                        }
                    }
                    return SuccessfulAuthentication(user, isNewUser, isNewConnection);
                }
            }
        }
开发者ID:bevacqua,项目名称:bruttissimo,代码行数:52,代码来源:OpenIdAuthenticationPortal.cs


示例18: GetUserIdentity

        private Interfaces.IAuthenticationResponse GetUserIdentity(IAuthenticationResponse response)
        {
            var identifier = response.ClaimedIdentifier;
            var fetch = response.GetExtension<FetchResponse>();
            Interfaces.IUserIdentity userIdentity = (fetch == null)
                ? null
                : Factory.GetUserIdentity(response.ClaimedIdentifier.ToString(),
                    fetch.GetAttributeValue(WellKnownAttributes.Name.First),
                    fetch.GetAttributeValue(WellKnownAttributes.Name.Last),
                    fetch.GetAttributeValue(WellKnownAttributes.Contact.Email));

            return Factory.AuthenticationResponse(userIdentity);
        }
开发者ID:binarymash,项目名称:OpenIdDemo,代码行数:13,代码来源:AuthenticationProvider.cs


示例19: UserInformation

 public UserInformation(IAuthenticationResponse response)
 {
     Response = response;
     ClaimedIdentifier = response.ClaimedIdentifier.ToString();
     if (response.Provider.Uri.Host == OpenIdHelper.Google)
     {
         SetUserInformationFromGoogle(response);
     }
     else
     {
         SetUserInformationGeneric(response);
     }
 }
开发者ID:phoenixwebgroup,项目名称:Accountability,代码行数:13,代码来源:UserInformation.cs


示例20: GetExtraData

		/// <summary>
		/// Gets the extra data obtained from the response message when authentication is successful.
		/// </summary>
		/// <param name="response">
		/// The response message. 
		/// </param>
		/// <returns>A dictionary of profile data; or null if no data is available.</returns>
		protected override NameValueCollection GetExtraData(IAuthenticationResponse response) {
			FetchResponse fetchResponse = response.GetExtension<FetchResponse>();
			if (fetchResponse != null) {
				var extraData = new NameValueCollection();
				extraData.AddItemIfNotEmpty("email", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.Email));
				extraData.AddItemIfNotEmpty("country", fetchResponse.GetAttributeValue(WellKnownAttributes.Contact.HomeAddress.Country));
				extraData.AddItemIfNotEmpty("firstName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.First));
				extraData.AddItemIfNotEmpty("lastName", fetchResponse.GetAttributeValue(WellKnownAttributes.Name.Last));

				return extraData;
			}

			return null;
		}
开发者ID:jiowei,项目名称:dotnetopenid,代码行数:21,代码来源:GoogleOpenIdClient.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IAuthenticationService类代码示例发布时间:2022-05-24
下一篇:
C# IAuthenticationRequest类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap