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


C# IAuthentication.Authenticate方法代码示例

本文整理汇总了C#中IAuthentication.Authenticate方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthentication.Authenticate方法的具体用法?C# IAuthentication.Authenticate怎么用?C# IAuthentication.Authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAuthentication的用法示例。


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

示例1: LogOn

        /// <summary>
        /// Logs on with specified authentication method.
        /// </summary>
        /// <param name="authentication">The authentication method.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">
        /// Already logged on
        /// or
        /// Another unfinished log on/off request exists.
        /// </exception>
        /// <exception cref="System.Exception">Null user info is not allowed</exception>
        public async Task LogOn(IAuthentication authentication)
        {

            if (UserInfo != null)
            {
                throw new InvalidOperationException("Already logged on");
            }
            if (Interlocked.CompareExchange(ref IsWorking, 1, 0) == 0)
            {
                try
                {
                    var result = await authentication.Authenticate();
                    if (result == null)
                    {
                        throw new Exception("Null user info is not allowed");
                    }
                    UserInfo = result;
                    ServerConnection.AccessToken = UserInfo.AccessToken;
                    return;
                }
                finally
                {
                    Interlocked.CompareExchange(ref IsWorking, 0, 1);
                }
            }
            throw new InvalidOperationException("Another unfinished log on/off request exists.");
        }
开发者ID:alexguo88,项目名称:Kfstorm.DoubanFM.Core,代码行数:38,代码来源:Session.cs

示例2: Login

		public static Credential Login(IAuthentication authentication, ICredentialProvider credentialProvider, string identity, string password, string @namespace, bool isRemember, out string redirectUrl)
		{
			if(authentication == null)
				throw new ArgumentNullException("authentication");

			if(credentialProvider == null)
				throw new ArgumentNullException("credentialProvider");

			//进行身份验证(即验证身份标识和密码是否匹配)
			var result = authentication.Authenticate(identity, password, @namespace);

			//注册用户凭证
			var credential = credentialProvider.Register(result.User, AuthenticationUtility.GetScene(), (result.HasExtendedProperties ? result.ExtendedProperties : null));

			//将注册成功的用户凭证保存到Cookie中
			AuthenticationUtility.SetCredentialCookie(credential, isRemember ? TimeSpan.FromDays(7) : TimeSpan.Zero);

			object redirectObject = null;

			//如果验证事件中显式指定了返回的URL,则使用它所指定的值
			if(result.HasExtendedProperties && result.ExtendedProperties.TryGetValue("RedirectUrl", out redirectObject) && redirectObject != null)
				redirectUrl = redirectObject.ToString();
			else //返回重定向的路径中
				redirectUrl = AuthenticationUtility.GetRedirectUrl(credential.Scene);

			return credential;
		}
开发者ID:Flagwind,项目名称:Zongsoft.Web,代码行数:27,代码来源:AuthenticationUtility.cs


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