question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to specify Scopes when using JSON key format

See original GitHub issue

I have tried to follow the documentation here: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#service-account to be able to connect to the API and create/upload new builds.

This is currently trying to use the: https://googleapis.dev/dotnet/Google.Apis.AndroidPublisher.v3/latest/api/Google.Apis.AndroidPublisher.v3.html

I believe I have followed through creating a Service account correctly as per the documentation however I am happy to accept I don’t really understand how it all pieces together yet. I have given Owner access to the main developer account for this account so I am assuming that is full access.

One different between the above linked example and my implementation is that I choose to use the “recommended key format” when creating a key for my Service Account and used JSON, hence my code example below:

private async Task Run(string packageName, string apiKey)
{
    ServiceAccountCredential credential;

    await using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
    {
        credential = ServiceAccountCredential.FromServiceAccountData(stream);
    }

    // Create the service.
    var service = new AndroidPublisherService(new BaseClientService.Initializer
    {
        ApplicationName = "App Uploader",
        HttpClientInitializer = credential,
        ApiKey = apiKey,
    });

    var appEdit = new AppEdit();

    // Fails here:
    var insertRequest = await service.Edits.Insert(appEdit, packageName).ExecuteAsync();
}

The //Fails here line throws the following exception:

Google.Apis.Requests.RequestError
The caller does not have permission [403]
Errors [
	Message[The caller does not have permission] Location[ - ] Reason[forbidden] Domain[global]
]

I can clearly see that I am not specifying a Scope when creating my credential now and when debugging I see that Scopes is empty. Do I need to be setting this somehow and if so am I able to do it using the JSON key format?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jskeetcommented, Dec 7, 2020

No problem - thanks for letting us know; it’s always nice to hear what worked in the end, and I’m glad the problem is solved 😃

1reaction
jskeetcommented, Dec 7, 2020

Not a problem at all - it’s always good to get some more information. I would suggest trying list or get calls to start with… those are normally easier to get to work, and then you can move on to insert/edit.

I’ll close this issue now as I suspect this isn’t actually a library auth issue, but please do add another comment with more details if you’d like us to reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using scopes and collections with cbimport sample format
I am using a shell script to configure Couchbase in a docker container. ... JSON import failed: the 'sample' format does not support...
Read more >
Using JSON Web Tokens as API Keys
Most APIs today use an API Key to authenticate legitimate clients. ... JSON Web Tokens gives you an homogenous token format across the...
Read more >
Parse JSON Formatted Logs
Since event is specified in the scope of the query, the json operator will only get logs that have event in them.
Read more >
Working with OAuth2 scopes | Apigee Edge
So, if a client receives a token that has READ scope, and it tries to call an API endpoint that requires WRITE access,...
Read more >
JSON | IntelliJ IDEA Documentation
IntelliJ IDEA helps you work with JSON files — it checks their syntax and formatting. ... In the Recognized File Types list, select...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found