Skip to content

Commit

Permalink
Added withFreshTokensPerformActionWithAdditionalParameters to OIDAuth…
Browse files Browse the repository at this point in the history
…State
  • Loading branch information
Craig Lane-RGD847 authored and WilliamDenniss committed Nov 8, 2016
1 parent d01f30b commit e6acfd9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Source/OIDAuthState.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ typedef void (^OIDAuthStateAuthorizationCallback)(OIDAuthState *_Nullable authSt
*/
- (void)withFreshTokensPerformAction:(OIDAuthStateAction)action;

/*! @fn performActionWithFreshTokens:additionalRefreshParameters:
@brief Calls the block with a valid access token (refreshing it first, if needed), or if a
refresh was needed and failed, with the error that caused it to fail.
@param action The block to execute with a fresh token. This block will be executed on the main thread.
@param additionalRefreshParameters Additional parameters for the token request if token is refreshed.
*/
- (void)performActionWithFreshTokens:(OIDAuthStateAction)action
additionalRefreshParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters;

/*! @fn setNeedsTokenRefresh
@brief Forces a token refresh the next time @c OIDAuthState.withFreshTokensPerformAction: is
called, even if the current tokens are considered valid.
Expand Down
8 changes: 7 additions & 1 deletion Source/OIDAuthState.m
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ - (void)setNeedsTokenRefresh {
}

- (void)withFreshTokensPerformAction:(OIDAuthStateAction)action {
[self performActionWithFreshTokens:action additionalRefreshParameters:nil];
}

- (void)performActionWithFreshTokens:(OIDAuthStateAction)action
additionalRefreshParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters {
if (!_refreshToken) {
[OIDErrorUtilities raiseException:kRefreshTokenRequestException];
}
Expand All @@ -434,7 +439,8 @@ - (void)withFreshTokensPerformAction:(OIDAuthStateAction)action {
}

// refresh the tokens
OIDTokenRequest *tokenRefreshRequest = [self tokenRefreshRequest];
OIDTokenRequest *tokenRefreshRequest =
[self tokenRefreshRequestWithAdditionalParameters:additionalParameters];
[OIDAuthorizationService performTokenRequest:tokenRefreshRequest
callback:^(OIDTokenResponse *_Nullable response,
NSError *_Nullable error) {
Expand Down

0 comments on commit e6acfd9

Please sign in to comment.