Exemple #1
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);
        }