Custom Server Behavior - Requests & Responses customisation #691
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What for ?
As I use OAuthSwift in some projects, I discover that certain OAuth provider may be not aware about being 100% Oauth2 compliant. For example, Withings new OAuth2 provider added some custom behavior, which are breaking changes:
Source: Deprecating access and refresh tokens endpoints (Withings support)
Custom get/refresh-token request parameters
Developer have to inject a custom parameter to tell what you want to do.
For a get/refresh-token request, the parameter is:
Custom get/refresh-token response
The get/refresh-token response is now a bit different: datas are encapsulated in an object
before
after
How
The goal of this PR is to add the ability to inject some datas, without touching existing behavior.
Custom get/refresh-token request parameters
OAuth2Swift init now support a new parameter, called
customAccessTokenParams
, which is nil by default.This parameter will be injected in the oauth client and, if exists, will add this dictionary in the parameter dictionary for get/refresh URL request
example:
the parameter is optional, so existing code will work as expected:
Custom get/refresh-token response
OAuth2Swift init now support a new parameter, called
customKeypath
, which is nil by default.This parameter will be used in the oauth client and, if exists, will modify the path where to get data (ie token, expiration.. so on) in the JSON response.
example:
the parameter is optional, so existing code will work as expected:
Bonus
In-project test app has been modified to play with tithings oauth2 too, only oauth was playable.