0
votes

I am trying to get access to the google drive content of my users. I can redeem a code on my domain using the google drive user consent url with correct parameters: https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id='+$scope.googledriveApi.client_id+'&scope='+$scope.googledriveApi.scopes+'&redirect_uri='+$scope.googledriveApi.redirect_uri

I am trying to do an angular $http request to the https://www.googleapis.com/oauth2/v4/token endpoint. The request looks like this:

$http({
     method: 'POST',
     headers: {"Content-Type" : "application/x-www-form-urlencoded"},
     data: $.param({
        "code" : $routeParams.code,
        "client_id" : $scope.googledriveApi.client_id,
        "client_secret" : $scope.googledriveApi.secret,
        "redirect_uri" : $scope.googledriveApi.redirect_uri,
        "grant_type" : "authorization_code"
     }),
     url: 'https://www.googleapis.com/oauth2/v4/token'
})

However the response I get from the request is as follows:

{
 "error": "invalid_client",
 "error_description": "The OAuth client was not found."
}

Does anyone know why this happens? I have tried changing product name and client id name to be the same. I have checked this for spaces. The reason I'm mentioning this is because this seemed to be the case for other people who asked a question for the same error, however my error happens at the $http request.

I am getting back the user consent code and I am trying to exchange for an access token in this request. This is when the error comes in and I am stuck.

1

1 Answers

0
votes

Try these:

  1. Under OAuth consent screen, make sure Product name is not the same with project name as stated in this SO thread:

enter image description here

  1. Try to include an authorization header in your URI request:

    headers: { 'Authorization': 'bearer ' + accessToken }