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.

Connection.request_token: missing_code-error despite single tenant application

See original GitHub issue

Hi there! I’m trying to deal with microsoft graph api via O365. As far as I understand the usage of an Authorization Code is not necessary when dealing with single tenant applications. My code is the following:

credentials = ('client_id', 'client_secret')
scopes = ['http://graph.microsoft.com/Mail.Read']
protocol_graph = MSGraphProtocol()
scopes_graph = protocol_graph.get_scopes_for(scopes)
con = Connection(credentials, scopes=scopes_graph, tenant_id='tenant_id')
url, state = con.get_authorization_url()
con.request_token(url)

request_token gives me: Unable to fetch auth token. Error: (missing_code) Missing code parameter in response. despite there’s no need of a code since dealing with single tenant application.

I’m able to get a token via:

payload = {'client_id': 'client_id',
           'client_secret': 'client_secret',
           'grant_type': 'client_credentials',
           'scope': 'Mail.Read'}

r = requests.get('https://login.microsoftonline.com/tenant_id/oauth2/token',
                 data=payload, headers={'Content-Type': 'application/x-www-form-urlencoded'})
token = json.loads(r.content)['access_token']

Is there a workaround to set the token manually without usage of request_token? Many thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:28 (28 by maintainers)

github_iconTop GitHub Comments

1reaction
janscascommented, Oct 18, 2019

Thank you very much @teamoo

1reaction
teamoocommented, Oct 18, 2019

With tenant = ‘common’ I get the following exception:

Unable to fetch auth token. Error: (unauthorized_client) AADSTS700016: Application with identifier 'XXXX-XXXX-XXXXX-XXXXXX' was not found in the directory 'microsoft.com'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.

So it is clear that the tenant id is definitely needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Single and multi-tenant apps in Azure AD - Microsoft Entra
In the Azure portal, you can configure your app to be single-tenant or multi-tenant by setting the audience as follows. Audience, Single/multi- ...
Read more >
What is Single-Tenancy? How's it Different from ... - TechTarget
In single-tenancy architectures, a customer -- called a tenant -- will have a singular instance of a SaaS application dedicated to them. In...
Read more >
Single Tenant vs Multi-Tenant Architecture - BMC Software
The architecture of a public cloud service can be shared across multiple tenants, whereas private cloud systems are dedicated for individual ...
Read more >
SaaS: Single Tenant vs Multi-Tenant - What's the Difference?
Each customer shares the software application and also shares a single database. Each tenant's data is isolated and remains invisible to other ...
Read more >
Single-Tenant vs Multi-Tenant: Which One to Go With? | Dialpad
Why choose a multi-tenant architecture SaaS application? ... when the software is installed locally (although you won't have access to the underlying code)....
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