Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Google OAuth 2.0 Authorization Framework Support adding custom header to Token Header request? #141

Closed
imben1109 opened this issue Jan 13, 2017 · 4 comments
Assignees
Labels
type: question Request for information or clarification. Not an issue.

Comments

@imben1109
Copy link

imben1109 commented Jan 13, 2017

I am using Google OAuth 2.0 Authorization Framework to obtain Github Access Token. It throw the following exception.

Exception in thread "main" java.lang.IllegalArgumentException:
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:889)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:382)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:355)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:82)
at com.techoffice.Appl.authorize(Appl.java:61)
at com.techoffice.Appl.main(Appl.java:68)
Caused by: java.lang.IllegalArgumentException: expected numeric type but got class com.google.api.client.auth.oauth2.TokenResponse
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:844)
... 9 more

The below would be my partial source code.

private static Credential authorize() throws IOException {

AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
HTTP_TRANSPORT, JSON_FACTORY, new GenericUrl(TOKEN_SERVER_URL),
new ClientParametersAuthentication(clientId, clientSecret), clientId, AUTHORIZATION_SERVER_URL)
.setScopes(Arrays.asList(SCOPE)).setDataStoreFactory(DATA_STORE_FACTORY).build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost(LOCALHOST).setPort(PORT).build();

return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");

}

I found the response of https://github.com/login/oauth/access_token would be in

access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&scope=user%2Cgist&token_type=bearer
Google OAuth would support JSON Format. To make Github response in JSON format, it required to add Accept: application/json in header.

How can I make it support in Github?

@mattwhisenhunt mattwhisenhunt added the type: question Request for information or clarification. Not an issue. label Jan 8, 2018
@mattwhisenhunt
Copy link
Contributor

@imben1109, have you found an answer already?

@imben1109
Copy link
Author

@mattwhisenhunt . No. It seems that it does not support custom access token.

@sduskis
Copy link

sduskis commented Dec 6, 2018

I'm going to change this to a feature request.

@sduskis sduskis added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Dec 6, 2018
@chingor13 chingor13 added type: question Request for information or clarification. Not an issue. and removed type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Dec 27, 2018
@chingor13
Copy link
Contributor

chingor13 commented Dec 27, 2018

What you want to do is configure your HttpRequestInitializer to set the header on the request.

Something like:

HttpRequestInitializer requestInitializer = new HttpRequestInitializer() {
  @Override
  public void initialize(HttpRequest request) throws IOException {
    HttpHeaders headers = request.getHeaders();
    headers.put("Accept", "application/json");
    request.setHeaders(headers);
  }
};
AuthorizationCodeFlow flow = 
    new AuthorizationCodeFlow.Builder(...) // fix these parameters
        .setRequestInitializer(requestInitializer)
        .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants