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


C# ICredentials.GetType方法代码示例

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


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

示例1: Login

    public IPromise<string> Login(ICredentials credentials, bool async)
    {
      var result = new Promise<string>();

      _lastCredentials = credentials;
      var database = string.Empty;
      var tokenCred = credentials as TokenCredentials;
      IPromise<IHttpResponse> loginPromise;

      if (tokenCred != null)
      {
        database = tokenCred.Database;
        loginPromise = PolicyToken(PolicyTokenType.connection, null, null, true)
          .Continue(p =>
          {
            return RenewSession(tokenCred.Content, p, true);
          });
      }
      else
      {
        var tokenPromise = (_lastLoginToken == null
                        || _lastLoginToken.Expiration > DateTime.UtcNow.AddSeconds(-5)) ?
        Query(null, null, null, this.SessionPolicy, null, async)
          .Convert<IHttpResponse, InitializeSessionToken>((r, p) =>
          {
            p.Reject(new Exception("Unauthorized error expected"));
          }, (ex, p) =>
          {
            var httpEx = ex as HttpException;
            if (httpEx != null
              && httpEx.Response.StatusCode == System.Net.HttpStatusCode.Forbidden)
            {
              var header = AuthenticationScheme.Parse(httpEx.Response.Headers["WWW-Authenticate"]);
              var auth = header.FirstOrDefault(a => a.Name == "bearer");
              if (auth == null) throw new InvalidOperationException();
              var ssoAuth = header.FirstOrDefault(a => a.Name == "winsso");

              _lastLoginToken = new InitializeSessionToken(auth.Parameters["token"]
                                      , auth.Parameters["nonce"], auth.Parameters["public_key"]);
              _lastLoginToken.SsoUrl = ssoAuth.Parameters["uri"];
              p.Resolve(_lastLoginToken);
            }
            else
            {
              p.Reject(ex);
            }
          }) :
        Promises.Resolved(_lastLoginToken);

      loginPromise = Promises.All(tokenPromise
                              , PolicyToken(PolicyTokenType.connection, null, null, async))
        .Continue(r =>
        {
          var winCred = credentials as WindowsCredentials;
          if (winCred == null)
          {
            SecureToken password = null;
            var username = string.Empty;

            var explicitCred = credentials as ExplicitCredentials;
            if (explicitCred != null)
            {
              database = explicitCred.Database;
              password = explicitCred.Password;
              username = explicitCred.Username;
            }
            else
            {
              var anon = credentials as AnonymousCredentials;
              if (anon != null)
              {
                database = anon.Database;
              }
              else
              {
                throw new ArgumentException(string.Format("Login credentials must be one of the built-in types, {0} is not supported"
                  , credentials == null, "NULL", credentials.GetType()), "credentials");
              }
            }

            string encodedData;
            var usernameLength = (username == null ? 0 : username.Length);
            var passwordLength = (password == null ? 0 : password.Length);
            var buffer = new byte[3 + 2 * (r.Result1.Nonce.Length + database.Length
                                            + usernameLength + passwordLength)];
            try
            {
              var i = Encoding.UTF8.GetBytes(r.Result1.Nonce, 0, r.Result1.Nonce.Length, buffer, 0);
              buffer[i++] = (byte)'|';
              i += Encoding.UTF8.GetBytes(database, 0, database.Length, buffer, i);
              buffer[i++] = (byte)'|';
              if (usernameLength > 0)
                i += Encoding.UTF8.GetBytes(username, 0, username.Length, buffer, i);
              buffer[i++] = (byte)'|';
              if (passwordLength > 0) password.UseBytes<bool>((ref byte[] b) =>
              {
                for (var j = 0; j < b.Length; j++)
                {
                  buffer[j + i] = b[j];
                }
//.........这里部分代码省略.........
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:101,代码来源:ProxyServerConnection.cs


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