Example #1
0
        /// <summary>
        /// Returns true if InputAuthRevoke instances are equal
        /// </summary>
        /// <param name="other">Instance of InputAuthRevoke to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(InputAuthRevoke other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Token == other.Token ||
                     Token != null &&
                     Token.Equals(other.Token)
                     ) &&
                 (
                     TokenTypeHint == other.TokenTypeHint ||
                     TokenTypeHint != null &&
                     TokenTypeHint.Equals(other.TokenTypeHint)
                 ) &&
                 (
                     ClientData == other.ClientData ||
                     ClientData != null &&
                     ClientData.Equals(other.ClientData)
                 ));
        }
Example #2
0
        private NdRevokeTokenResponse RevokeToken(string token, TokenTypeHint hint, string host = null)
        {
            var accessToken = clientData.GetSavedAccessToken(clientData.GetClientId());

            return(oAuth.RevokeToken(accessToken, token, hint, host)
                   .ToResultOrException());
        }
Example #3
0
        /// <summary>
        /// This function gets access token with post request
        /// </summary>
        public bool RevokeToken(TokenTypeHint tokenType, String token)
        {
            TokenTypeHint t = tokenType;

            var query = HttpUtility.ParseQueryString(String.Empty);

            string oauthParameters = String.Empty;

            switch (t)
            {
            case TokenTypeHint.AccessToken:

                query["client_id"]       = apiKey;
                query["client_secret"]   = secretKey;
                query["token"]           = token;
                query["token_type_hint"] = "access_token";

                break;

            case TokenTypeHint.RefreshToken:

                query["client_id"]       = apiKey;
                query["client_secret"]   = secretKey;
                query["token"]           = token;
                query["token_type_hint"] = "refresh_token";

                break;
            }
            oauthParameters = query.ToString();

            if (!String.IsNullOrEmpty(oauthParameters))
            {
                var revokeService = new APIService(endPoint, "/oauth/v4/");
                var apiRequest    = new APIRequest("revoke");

                apiRequest.requireAccessToken = false;
                apiRequest.contentType        = "application/x-www-form-urlencoded";
                apiRequest.setBinaryData(oauthParameters);


                if (revokeService.post(apiRequest))
                {
                    return(true);
                }
            }

            throw new Exception(apiService.errorResponse);
        }
Example #4
0
        public async Task <bool> RevocationTokenAsync(string token, TokenTypeHint tokenType)
        {
            var endpoints = await GetDiscoveryDocumentAsync();

            var tokenRevokeResponse = await _httpClient.RevokeTokenAsync(new TokenRevocationRequest()
            {
                Address       = endpoints.RevocationEndpoint,
                ClientId      = _options.Value.ClientId,
                ClientSecret  = _options.Value.ClientSecret,
                TokenTypeHint = tokenType.Value,
                Token         = token
            });

            if (tokenRevokeResponse.IsError || tokenRevokeResponse.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                return(false);
            }
            return(true);
        }
Example #5
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Token != null)
         {
             hashCode = hashCode * 59 + Token.GetHashCode();
         }
         if (TokenTypeHint != null)
         {
             hashCode = hashCode * 59 + TokenTypeHint.GetHashCode();
         }
         if (ClientData != null)
         {
             hashCode = hashCode * 59 + ClientData.GetHashCode();
         }
         return(hashCode);
     }
 }
Example #6
0
        /// <summary>
        /// This function gets access token with post request
        /// </summary>
        public bool RevokeToken(TokenTypeHint tokenType, String token)
        {
            TokenTypeHint t = tokenType;

            var query = HttpUtility.ParseQueryString(String.Empty);

            string oauthParameters = String.Empty;

            switch (t)
            {
                case TokenTypeHint.AccessToken:

                    query["client_id"] = apiKey;
                    query["client_secret"] = secretKey;
                    query["token"] = token;
                    query["token_type_hint"] = "access_token";

                    break;

                case TokenTypeHint.RefreshToken:

                    query["client_id"] = apiKey;
                    query["client_secret"] = secretKey;
                    query["token"] = token;
                    query["token_type_hint"] = "refresh_token";

                    break;
            }
            oauthParameters = query.ToString();

            if (!String.IsNullOrEmpty(oauthParameters))
            {
                var revokeService = new APIService(endPoint, "/oauth/v4/");
                var apiRequest = new APIRequest("revoke");

                apiRequest.requireAccessToken = false;
                apiRequest.contentType = "application/x-www-form-urlencoded";
                apiRequest.setBinaryData(oauthParameters);

                if (revokeService.post(apiRequest))
                {
                    return true;
                }
            }

            throw new Exception(apiService.errorResponse);
        }