NetIQ Mobile SDK for iOS  2.0
Access Manager iOS Framework for OAuth & OIDC
MFAuthService.h
1 //
2 // MFAuthService.h
3 // MFAuthLib
4 //
5 // Created by MicroFocus on 1/26/17.
6 // Copyright © 2017 Microfocus. All rights reserved.
7 //
8 
9 #import <Foundation/Foundation.h>
10 @import SafariServices;
11 
12 #import "MFServiceConfiguration.h"
13 #import "MFUtil.h"
14 
15 //#import <AppAuthLib/AppAuth.h>
16 
17 @protocol OIDAuthorizationFlowSession;
18 
19 @class OIDAuthState;
20 
26 typedef void (^MFDiscoveryCallback)(MFServiceConfiguration *_Nullable configuration, NSError *_Nullable error);
27 
28 typedef void (^MFAuthorizationFlowCallback)(id<OIDAuthorizationFlowSession> _Nullable currentAuthFlowSession,
29 NSError *_Nullable error);
30 
35 typedef void (^MFSignInCompletionCallback)(BOOL success, NSError *_Nullable error);
36 
42 typedef void (^MFResponseCallback)(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error);
43 
48 typedef void (^MFUserInfoCallback)(NSDictionary *_Nullable dictUserData, NSError *_Nullable error);
49 
55 typedef void (^MFAuthStateAction)(NSString *_Nullable accessToken, NSString *_Nullable idToken, NSError *_Nullable error);
56 
57 
58 
61 @interface MFAuthService : NSObject <SFSafariViewControllerDelegate>
62 
63 @property(nonatomic, readonly, nullable) OIDAuthState *authState;
64 
65 @property(nonatomic, readonly, nullable) OIDServiceConfiguration *OIDConfig;
66 
73 @property(nonatomic, readonly, nullable) MFServiceConfiguration *config;
74 
75 
83 + (void) discoverServiceConfiguration:(nonnull NSURL *) discoveryUrl completion:(nonnull MFDiscoveryCallback) completionCallback;
84 
88 + (void) removeKeychainEntry;
89 
90 
91 - (nullable instancetype) init NS_UNAVAILABLE;
92 
93 
98 - (nullable instancetype) initWithServiceConfig:(nonnull MFServiceConfiguration *) serviceConfig
99  NS_DESIGNATED_INITIALIZER;
100 
107 - (nullable instancetype) initWithAuthzEndpoint:(nonnull NSURL *) authorizationUrl
108  tokenEndpoint:(nonnull NSURL *) tokenUrl
109  revocationEndpoint:(nullable NSURL *) revocationUrl
110  userinfoEndpoint:(nullable NSURL *) userinfoUrl;
111 
119 - (nullable instancetype) initWithAuthzEndpoint:(nonnull NSURL *) authorizationUrl
120  tokenEndpoint:(nonnull NSURL *) tokenUrl
121  revocationEndpoint:(nullable NSURL *) revocationUrl
122  userinfoEndpoint:(nullable NSURL *) userinfoUrl
123  browserLogoutEndpoint:(nullable NSURL *) browserLogoutUrl;
124 
129 - (nullable instancetype) initWithProvider:(nonnull NSURL *) providerBaseUrl;
130 
136 - (nullable instancetype) initWithIssuerUrl:(nonnull NSURL *) issuerUrl
137  logoutUrl:(nullable NSURL *) logoutUrl;
138 
142 - (BOOL) isAuthorized;
143 
146 - (void)setAuthState:(nullable OIDAuthState *)authState;
147 
150 - (void) loadState;
151 
154 - (void) saveState;
155 
169 - (nullable id<OIDAuthorizationFlowSession>) signInWithClientId:(nonnull NSString *) clientId
170  clientSecret:(nullable NSString *) clientSecret
171  scopes:(nullable NSArray<NSString *> *) scopes
172  redirectURL:(nullable NSURL *) redirectURL
173  presentingViewController:(nonnull UIViewController *) presentingVC
174  withBlock:(nonnull MFSignInCompletionCallback) callbackBlock;
175 
191 - (nullable id<OIDAuthorizationFlowSession>) signInWithClientId:(nonnull NSString *) clientId
192  clientSecret:(nullable NSString *) clientSecret
193  scopes:(nullable NSArray<NSString *> *) scopes
194  redirectURL:(nullable NSURL *) redirectURL
195  responseType:(nullable NSString *) responseType
196  additionalParameters:(nullable NSMutableDictionary<NSString *, NSString *> *) additionalParameters
197  presentingViewController:(nonnull UIViewController *) presentingVC
198  withBlock:(nonnull MFSignInCompletionCallback) callbackBlock;
199 
205 - (void) getUserInfoResponse:(nonnull MFResponseCallback) completionHandler;
206 
212 - (void) getUserInfo:(nonnull MFUserInfoCallback) completionHandler;
213 
218 - (void) performActionWithFreshToken:(nonnull MFAuthStateAction) action;
219 
225 - (void) performHTTPRequestWithFreshToken:(nonnull NSURL *) requestUrl
226  withCompletionHandler:(nonnull MFResponseCallback) handler;
227 
230 - (nullable NSString *) getAccessToken;
231 
234 - (nullable NSString *) getAccessTokenExpiryTimeString;
235 
244 - (void) logout:(nonnull UIViewController *) presentingVC;
245 
248 - (void) revokeToken:(nonnull NSURL *) revocationEndpoint;
249 
250 
251 @end
void loadState()
load state with tokens from device keychain
Definition: MFAuthService.m:192
Represents the information needed to construct a OIDAuthorizationService.
Definition: OIDServiceConfiguration.h:35
void saveState()
save state with tokens to device keychain
Definition: MFAuthService.m:182
nullable NSString * getAccessToken()
Get the access token.
Definition: MFAuthService.m:525
void removeKeychainEntry()
Remove an existing Keychain entry with tokens. This can be used for e.g. when the orphaned tokens nee...
Definition: MFAuthService.m:54
nullable NSString * getAccessTokenExpiryTimeString()
Get the access token expiration time string in local time.
Definition: MFAuthService.m:534
This extends the OIDServiceConfiguration class and adds few additional properties.
Definition: MFServiceConfiguration.h:13
A convenience class that retains the auth state between OIDAuthorizationResponses and OIDTokenRespons...
Definition: OIDAuthState.h:54
MFServiceConfiguration * config
The service&#39;s configuration.
Definition: MFAuthService.h:73
BOOL isAuthorized()
Is already authorized.
Definition: MFAuthService.m:164
Performs various OAuth and OpenID Connect related calls via the user agent or .
Definition: MFAuthService.h:61