AppAuth
OIDAuthState.h
Go to the documentation of this file.
1 
18 #import <Foundation/Foundation.h>
19 
22 @class OIDAuthState;
24 @class OIDTokenResponse;
25 @class OIDTokenRequest;
28 @protocol OIDExternalUserAgent;
30 
31 NS_ASSUME_NONNULL_BEGIN
32 
38 typedef void (^OIDAuthStateAction)(NSString *_Nullable accessToken,
39  NSString *_Nullable idToken,
40  NSError *_Nullable error);
41 
48 typedef void (^OIDAuthStateAuthorizationCallback)(OIDAuthState *_Nullable authState,
49  NSError *_Nullable error);
50 
54 @interface OIDAuthState : NSObject <NSSecureCoding>
55 
62 @property(nonatomic, readonly, nullable) NSString *refreshToken;
63 
69 @property(nonatomic, readonly, nullable) NSString *scope;
70 
74 @property(nonatomic, readonly) OIDAuthorizationResponse *lastAuthorizationResponse;
75 
79 @property(nonatomic, readonly, nullable) OIDTokenResponse *lastTokenResponse;
80 
84 @property(nonatomic, readonly, nullable) OIDRegistrationResponse *lastRegistrationResponse;
85 
94 @property(nonatomic, readonly, nullable) NSError *authorizationError;
95 
105 @property(nonatomic, readonly) BOOL isAuthorized;
106 
111 @property(nonatomic, weak, nullable) id<OIDAuthStateChangeDelegate> stateChangeDelegate;
112 
117 @property(nonatomic, weak, nullable) id<OIDAuthStateErrorDelegate> errorDelegate;
118 
133  authStateByPresentingAuthorizationRequest:(OIDAuthorizationRequest *)authorizationRequest
134  externalUserAgent:(id<OIDExternalUserAgent>)externalUserAgent
135  callback:(OIDAuthStateAuthorizationCallback)callback;
136 
140 - (instancetype)init NS_UNAVAILABLE;
141 
145 - (instancetype)initWithAuthorizationResponse:(OIDAuthorizationResponse *)authorizationResponse;
146 
151 - (instancetype)initWithAuthorizationResponse:(OIDAuthorizationResponse *)authorizationResponse
152  tokenResponse:(nullable OIDTokenResponse *)tokenResponse;
153 
157 - (instancetype)initWithRegistrationResponse:(OIDRegistrationResponse *)registrationResponse;
158 
164 - (instancetype)initWithAuthorizationResponse:
165  (nullable OIDAuthorizationResponse *)authorizationResponse
166  tokenResponse:(nullable OIDTokenResponse *)tokenResponse
167  registrationResponse:(nullable OIDRegistrationResponse *)registrationResponse
168  NS_DESIGNATED_INITIALIZER;
169 
178 - (void)updateWithAuthorizationResponse:(nullable OIDAuthorizationResponse *)authorizationResponse
179  error:(nullable NSError *)error;
180 
189 - (void)updateWithTokenResponse:(nullable OIDTokenResponse *)tokenResponse
190  error:(nullable NSError *)error;
191 
197 - (void)updateWithRegistrationResponse:(nullable OIDRegistrationResponse *)registrationResponse;
198 
212 - (void)updateWithAuthorizationError:(NSError *)authorizationError;
213 
219 - (void)performActionWithFreshTokens:(OIDAuthStateAction)action;
220 
228 - (void)performActionWithFreshTokens:(OIDAuthStateAction)action
229  additionalRefreshParameters:
230  (nullable NSDictionary<NSString *, NSString *> *)additionalParameters;
231 
240 - (void)performActionWithFreshTokens:(OIDAuthStateAction)action
241  additionalRefreshParameters:
242  (nullable NSDictionary<NSString *, NSString *> *)additionalParameters
243  dispatchQueue:(dispatch_queue_t)dispatchQueue;
244 
248 - (void)setNeedsTokenRefresh;
249 
258 
267 - (nullable OIDTokenRequest *)tokenRefreshRequestWithAdditionalParameters:
268  (nullable NSDictionary<NSString *, NSString *> *)additionalParameters;
269 
270 @end
271 
272 NS_ASSUME_NONNULL_END
OIDAuthState::lastAuthorizationResponse
OIDAuthorizationResponse * lastAuthorizationResponse
The most recent authorization response used to update the authorization state. For the implicit flow,...
Definition: OIDAuthState.h:74
OIDAuthStateErrorDelegate-p
Delegate of the OIDAuthState used to monitor errors.
Definition: OIDAuthStateErrorDelegate.h:28
OIDAuthorizationResponse
Represents the response to an authorization request.
Definition: OIDAuthorizationResponse.h:31
-[OIDAuthState tokenRefreshRequest]
nullable OIDTokenRequest * tokenRefreshRequest()
Creates a token request suitable for refreshing an access token.
OIDAuthStateChangeDelegate-p
Delegate of the OIDAuthState used to monitor various changes in state.
Definition: OIDAuthStateChangeDelegate.h:28
OIDAuthorizationRequest
Represents an authorization request.
Definition: OIDAuthorizationRequest.h:41
OIDAuthState::refreshToken
NSString * refreshToken
The most recent refresh token received from the server. @discussion Rather than using this property d...
Definition: OIDAuthState.h:62
OIDAuthStateAuthorizationCallback
void(^ OIDAuthStateAuthorizationCallback)(OIDAuthState *_Nullable authState, NSError *_Nullable error)
The method called when the authStateByPresentingAuthorizationRequest:presentingViewController:callbac...
Definition: OIDAuthState.h:48
OIDAuthState::isAuthorized
BOOL isAuthorized
Returns YES if the authorization state is not known to be invalid. @discussion Returns YES if no OAut...
Definition: OIDAuthState.h:105
OIDAuthState::authorizationError
NSError * authorizationError
The authorization error that invalidated this OIDAuthState. @discussion The authorization error encou...
Definition: OIDAuthState.h:94
OIDRegistrationResponse
Represents a registration response.
Definition: OIDRegistrationResponse.h:53
OIDAuthState::scope
NSString * scope
The scope of the current authorization grant. @discussion This represents the latest scope returned b...
Definition: OIDAuthState.h:69
OIDExternalUserAgentSession-p
Represents an in-flight external user-agent session.
Definition: OIDExternalUserAgentSession.h:23
OIDTokenRequest
Represents a token request.
Definition: OIDTokenRequest.h:34
OIDAuthState
A convenience class that retains the auth state between OIDAuthorizationResponses and OIDTokenRespons...
Definition: OIDAuthState.h:54
OIDAuthState::lastRegistrationResponse
OIDRegistrationResponse * lastRegistrationResponse
The most recent registration response used to update this authorization state. This will contain the ...
Definition: OIDAuthState.h:84
OIDAuthState::lastTokenResponse
OIDTokenResponse * lastTokenResponse
The most recent token response used to update this authorization state. This will contain the latest ...
Definition: OIDAuthState.h:79
-[OIDAuthState setNeedsTokenRefresh]
void setNeedsTokenRefresh()
Forces a token refresh the next time performActionWithFreshTokens: is called, even if the current tok...
OIDAuthStateAction
void(^ OIDAuthStateAction)(NSString *_Nullable accessToken, NSString *_Nullable idToken, NSError *_Nullable error)
Represents a block used to call an action with a fresh access token.
Definition: OIDAuthState.h:38
OIDTokenResponse
Represents the response to an token request.
Definition: OIDTokenResponse.h:29
OIDAuthState::errorDelegate
id< OIDAuthStateErrorDelegate > errorDelegate
The OIDAuthStateErrorDelegate delegate. @discussion Use the delegate to observe state changes (and up...
Definition: OIDAuthState.h:117
OIDExternalUserAgent-p
An external user-agent UI that presents displays the request to the user. Clients may provide custom ...
Definition: OIDExternalUserAgent.h:31
OIDAuthState::stateChangeDelegate
id< OIDAuthStateChangeDelegate > stateChangeDelegate
The OIDAuthStateChangeDelegate delegate. @discussion Use the delegate to observe state changes (and u...
Definition: OIDAuthState.h:111