【发布时间】:2018-10-02 09:10:39
【问题描述】:
我需要与 HMRC(英国内陆税收)REST API 进行交互。他们给了我Java中的示例代码,谁能帮我把它翻译成C#?我假设我必须将客户端 ID、客户端密码、重定向 Uri 和授权代码添加到 HttpClient 或 HttpRequest 但我被卡住了。 提前致谢。 吉姆。
这是 Java 示例:
// extract the authorization code from the request querystring
OAuthAuthzResponse response =
OAuthAuthzResponse.oauthCodeAuthzResponse(httpServletRequest);
String authorizationCode = response.getCode();
// create OAuth 2.0 Client using Apache HTTP Client
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
// construct OAuth 2.0 Token request for the authorization code
OAuthClientRequest request = OAuthClientRequest
.tokenLocation("https://test-api.service.hmrc.gov.uk/oauth/token")
.setGrantType(GrantType.AUTHORIZATION_CODE)
.setClientId(clientId)
.setClientSecret(clientSecret)
.setRedirectURI(redirectUri)
.setCode(authorizationCode)
.buildBodyMessage();
// request the token via the OAuth 2.0 client
OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
// extract the data from the response
String accessToken = response.getAccessToken();
String refreshToken = response.getRefreshToken();
String grantedScope = response.getScope();
Long expiresIn = response.getExpiresIn();
【问题讨论】:
标签: java c# apache http-request-parameters