mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[GH-ISSUE #721] OAuth2 and Microsoft Graph Api error: The request body must contain the following parameter: 'grant_type'. #467
Labels
No labels
bug
cocoapod
duplicate
enhancement
feature-request
help wanted
help wanted
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/OAuthSwift#467
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mixable on GitHub (Jun 25, 2024).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/721
Description:
Ii want to use this lib for OAuth2 and Office 365 (Microsoft Graph Api). The implementation looks like this:
The initial authorization works as expected. But when it comes to a token renewal using the
refresh_token, the auth request tohttps://login.microsoftonline.com/common/oauth2/v2.0/tokenfails with the following requestError:The reason is the parameter
grant_typewhich is not in the body. With different settings, I was not able to get rid of this error. Do you have any ideas how to solve this issue? Or how to configure the OAuth2Swift object for Microsofts Graph Api?This is the documentation of Microsofts Graph Api and OAuth2:
https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http#5-use-the-refresh-token-to-renew-an-expired-access-token
I also found this discussion on StackOverflow:
https://stackoverflow.com/questions/49513122/oauth2-error-aadsts90014-the-request-body-must-contain-the-following-parameter
OAuth Provider? (Twitter, Github, ..):
Office 365 / Microsoft Graph Api
OAuth Version:
OS (Please fill the version) :
Installation method:
Library version:
Xcode version:
11.4 (Swift 5.2)
11.x (Swift 5.1)
10.x (Swift 5.0)
other: (Please fill in the version you are using.)
objective c
@phimage commented on GitHub (Jun 25, 2024):
hi, code used to renew token?
grant type is added in parameters for renewAccessToken
https://github.com/OAuthSwift/OAuthSwift/blob/master/Sources/OAuthSwiftClient.swift#L201
do not know if passed as body or query parameters
@mixable commented on GitHub (Jun 25, 2024):
The request is started with startAuthorizedRequest(). This will automatically call renewAccessToken() if the access token expired.
The code for the authorized request is:
I think, this way the parameters are passed as query parameters.
I saw that the method startAuthorizedRequest also provides the option
renewHeaders:. I didn't use this before, but I added the form data content type to the renewHeaders:And what should I say: with this, the token renewal worked as expected!!
Thank you for pointing me to this!!