diff --git a/Sources/AppAuthCore/OIDAuthState.h b/Sources/AppAuthCore/OIDAuthState.h index 46c78a831..eafd82a97 100644 --- a/Sources/AppAuthCore/OIDAuthState.h +++ b/Sources/AppAuthCore/OIDAuthState.h @@ -248,6 +248,48 @@ static NSString *const kRefreshTokenRequestException = (nullable NSDictionary *)additionalParameters dispatchQueue:(dispatch_queue_t)dispatchQueue; +/*! @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 additionalHeaders Additional parameters for the token request if token is + refreshed. + */ +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders; + +/*! @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 additionalHeaders Additional parameters for the token request if token is + refreshed. + @param dispatchQueue The dispatchQueue on which to dispatch the action block. + */ +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders + dispatchQueue:(dispatch_queue_t)dispatchQueue; + +/*! @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 additionalParameters Additional parameters for the token request if token is + refreshed. + @param additionalHeaders Additional parameters for the token request if token is + refreshed. + @param dispatchQueue The dispatchQueue on which to dispatch the action block. + */ +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshParameters: + (nullable NSDictionary *)additionalParameters + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders + dispatchQueue:(dispatch_queue_t)dispatchQueue; + + /*! @brief Forces a token refresh the next time @c OIDAuthState.performActionWithFreshTokens: is called, even if the current tokens are considered valid. */ diff --git a/Sources/AppAuthCore/OIDAuthState.m b/Sources/AppAuthCore/OIDAuthState.m index cb5a22a1e..53fac07b0 100644 --- a/Sources/AppAuthCore/OIDAuthState.m +++ b/Sources/AppAuthCore/OIDAuthState.m @@ -506,6 +506,36 @@ - (void)performActionWithFreshTokens:(OIDAuthStateAction)action additionalRefreshParameters: (nullable NSDictionary *)additionalParameters dispatchQueue:(dispatch_queue_t)dispatchQueue { + [self performActionWithFreshTokens:action + additionalRefreshParameters:additionalParameters + additionalRefreshHeaders:nil + dispatchQueue:dispatch_get_main_queue()]; +} + +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders { + [self performActionWithFreshTokens:action + additionalRefreshHeaders:additionalHeaders + dispatchQueue:dispatch_get_main_queue()]; +} + +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders + dispatchQueue:(dispatch_queue_t)dispatchQueue { + [self performActionWithFreshTokens:action + additionalRefreshParameters:nil + additionalRefreshHeaders:additionalHeaders + dispatchQueue:dispatch_get_main_queue()]; +} + +- (void)performActionWithFreshTokens:(OIDAuthStateAction)action + additionalRefreshParameters: + (nullable NSDictionary *)additionalParameters + additionalRefreshHeaders: + (nullable NSDictionary *)additionalHeaders + dispatchQueue:(dispatch_queue_t)dispatchQueue { if ([self isTokenFresh]) { // access token is valid within tolerance levels, perform action @@ -544,7 +574,8 @@ - (void)performActionWithFreshTokens:(OIDAuthStateAction)action // refresh the tokens OIDTokenRequest *tokenRefreshRequest = - [self tokenRefreshRequestWithAdditionalParameters:additionalParameters]; + [self tokenRefreshRequestWithAdditionalParameters:additionalParameters + additionalHeaders:additionalHeaders]; [OIDAuthorizationService performTokenRequest:tokenRefreshRequest originalAuthorizationResponse:_lastAuthorizationResponse callback:^(OIDTokenResponse *_Nullable response,