I am trying to simply authenticate to the Google Cloud Storage API using OAuth2.0 and C# with a JSON file from Google.
here is my OAuth JSON file:
{
"client_id": "ClientIdHere",
"project_id": "ProjectName",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "ClientSecretHere",
"redirect_uris": [ "https://localhost:44349//RedirectPage.aspx" ]
}
Here is the code that I am using, I borrowed it from this post
protected void DoTheThingsAgain()
{
try
{
string bucketName = "Daves-Bucket";
string sharedkeyFilePath = "C:\\inetpub\\wwwroot\\GoogleAPITest\\GoogleAPITest\\App_Data\\JSONFile.json";
GoogleCredential credential = null;
using (var jsonStream = new FileStream(sharedkeyFilePath, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(jsonStream);
}
}
catch (Exception ex)
{
throw ex;
}
}
Everything works fine until it hits this line:
**credential = GoogleCredential.FromStream(jsonStream);**
then it gives me the error: Error creating credential from JSON. Unrecognized credential type .
How do I specify the credential type for OAuth?
I have seen other solutions for this but not while using OAuth, only with ServiceAccounts.
That you in advance for any help you all can provide!