示例#1
0
        /// <inheritdoc/>
        public override AuthToken Authenticate(MdlpClient apiClient)
        {
            // get authentication code
            var authCode = apiClient.Authenticate(ClientID, ClientSecret, UserID, AuthTypeEnum.PASSWORD);

            // get authentication token
            return(apiClient.GetToken(authCode, password: Password));
        }
        /// <inheritdoc/>
        public override AuthToken Authenticate(MdlpClient apiClient)
        {
            // load the certificate with a private key by userId
            var certificate = apiClient.UserCertificate;

            if (certificate == null)
            {
                throw new SecurityException("GOST-compliant certificate not found. " +
                                            "Make sure that the certificate is properly installed and has the associated private key. " +
                                            "Thumbprint or subject name: " + UserID);
            }

            // get authentication code
            var authCode = apiClient.Authenticate(ClientID, ClientSecret, UserID, AuthTypeEnum.SIGNED_CODE);

            // compute the signature and save the size
            var signature = GostCryptoHelpers.ComputeDetachedSignature(certificate, authCode);

            apiClient.SignatureSize = Encoding.UTF8.GetByteCount(signature);

            // get authentication token
            return(apiClient.GetToken(authCode, signature: signature));
        }
示例#3
0
 public CredentialsAuthenticator(MdlpClient apiClient, CredentialsBase credentials)
 {
     State       = AuthState.NotAuthenticated;
     Client      = apiClient;
     Credentials = credentials;
 }
 /// <summary>
 /// Performs authentication, returns access token with a limited lifetime.
 /// </summary>
 /// <param name="apiClient">MDLP client to perform API calls.</param>
 /// <returns><see cref="AuthToken"/> instance.</returns>
 public abstract AuthToken Authenticate(MdlpClient apiClient);