1

我正在使用 AppAuth 库在我的应用程序中以目标 c 编写的自定义单点登录。

到目前为止,我已经设法让它快速工作,但是当我使用转换为目标 c 的相同代码时,浏览器没有打开。这是我到目前为止所拥有的(已经从这里包含的代码中删除了所有 url 和 id,所以不要介意这里的字符串是空的):

在应用委托中:

@property(nonatomic, strong, nullable) id<OIDExternalUserAgentSession> currentAuthorizationFlow;

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
// Sends the URL to the current authorization flow (if any) which will process it if it relates to
// an authorization response.
if ([_currentAuthorizationFlow resumeExternalUserAgentFlowWithURL:url]) {
    _currentAuthorizationFlow = nil;
    return YES;
}

return NO;
}

在视图控制器中:

- (IBAction)loginButtonAction:(id)sender {
NSURL *authorizationEndpoint = [NSURL URLWithString:@""];
NSURL *tokenEndpoint = [NSURL URLWithString:@""];

OIDServiceConfiguration *configuration = [[OIDServiceConfiguration alloc] initWithAuthorizationEndpoint:authorizationEndpoint tokenEndpoint:tokenEndpoint];

NSString *clientId = @"";
NSURL *redirectUri = [NSURL URLWithString:@""];

OIDAuthorizationRequest *builder = [[OIDAuthorizationRequest alloc] initWithConfiguration:configuration clientId:clientId scopes:@[OIDScopeOpenID] redirectURL:redirectUri responseType:OIDResponseTypeCode additionalParameters:nil];

// performs authentication request
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
appDelegate.currentAuthorizationFlow = [OIDAuthState authStateByPresentingAuthorizationRequest:builder presentingViewController:self callback:^(OIDAuthState *_Nullable authState, NSError *_Nullable error) {
    if (authState) {
        NSLog(@"Got authorization tokens. Access token: %@", authState.lastTokenResponse.accessToken);
    } else {
        NSLog(@"Authorization error: %@", [error localizedDescription]);
    }
}];
}

这会打开一个警报,询问用户他/她是否要登录,如果我按继续,外部浏览器应该会打开自定义 SSO 页面。问题是按下继续后没有任何反应。

有任何想法吗?

4

1 回答 1

0

检查您的配置和请求中的参数,尤其是发行者。不存储 currentAuthorizationFlow 也停止了我的流程。

hth。

于 2019-06-25T14:27:09.840 回答