2

I'm trying to authorize in google using .NET SDK provided, but it failes with "Invalid credentials" error. I found this answer

Google Calendar V3 2 Legged authentication fails

but I still don't see where is the mistake. Looks like everything is done as described.

Here is my code

const string CONSUMER_KEY = "mytestdomain.com";
const string CONSUMER_SECRET = "my_consumer_secret";
const string TARGET_USER = "user";
const string SERVICE_KEY = "some_api_key";

var auth = new OAuth2LeggedAuthenticator(CONSUMER_KEY, CONSUMER_SECRET, TARGET_USER, CONSUMER_KEY);

var service = new DriveService(auth) { Key = SERVICE_KEY };
var results = service.Files.List().Fetch();

Console.WriteLine(results.Items.Count);

and here are screenshots from google control panel. I just replaced domain name, consumer key and api key.

Screenshot from Manage API client access page Screenshot from "Manage API client access" page

Screenshot from Manage OAuth key and secret for this domain page Screenshot from "Manage OAuth key and secret for this domain" page

Screenshot from API Access page in Google API console Screenshot from "API Access" page in "Google API console"

Community
  • 1
  • 1
axe
  • 2,331
  • 4
  • 31
  • 53
  • I assume you have looked at this question: http://stackoverflow.com/questions/11556875/google-drive-api-using-google-apis-authentication?rq=1 and of course https://developers.google.com/drive/ – Security Hound Dec 06 '12 at 12:09
  • I don't get what you mean. The first link says where to download the DLL, the second one contains some examples and documentation. I'm not asking where to download it, it is already downloaded, added as reference to the project and it works. I just can't authorize, because it gives me "Invalid Credentials" error. – axe Dec 06 '12 at 12:13
  • The reason I asked is because the Google Drive API is difference then the Google Calendar API the question you made mention of is using. What happens when you click on "Allow access to all APIs"? – Security Hound Dec 06 '12 at 12:20
  • Nothing. I get the same error. – axe Dec 06 '12 at 12:27

1 Answers1

1

OAuth 1.0 has been deprecated and 2-Legged OAuth 1.0 with it. Although it is still supported for the deprecation period if I were you I would use Service Accounts with OAuth 2.0 to perform domain-wide delegation of authority.

This is very well documented on the Perform Google Apps Domain-wide Delegation of Authority page of the Google Drive SDK documentation.

Nicolas Garnier
  • 12,134
  • 2
  • 42
  • 39