저는 Azure-Samples / active-directory-b2c-ios-swift-native-msal 앱을 사용하여 Azure B2C 테넌트의 기능을 데모하기 시작했습니다. 새로 고침 토큰 기능 외부에서 모든 작업을 수행했습니다. 새로 고침 토큰이 제공되도록 "offline_access"범위를 추가했습니다.
내가 얻은 첫 번째 오류 :
let application = try MSALPublicClientApplication.init(clientId: kClientID, authority: kAuthority)
let thisUser = try self.getUserByPolicy(withUsers: application.users(), forPolicy: kSignupOrSigninPolicy)
application.acquireTokenSilent(forScopes: kScopes, user: thisUser) { (result, error) in
if error == nil {
self.accessToken = (result?.accessToken)!
self.loggingText.text = "Refreshing token silently"
self.loggingText.text = "Refreshed Access token is \(self.accessToken)"
}
그래서 초기 인증에서 MSAL 사용자를 저장하고 AcquireTokenSilent 메서드에 전달했습니다.
이 오류가 발생합니다.
let application = try MSALPublicClientApplication.init(clientId: kClientID, authority: kAuthority)
let thisUser = userFromAuth
application.acquireTokenSilent(forScopes: kScopes, user: thisUser) { (result, error) in
if error == nil {
self.accessToken = (result?.accessToken)!
self.loggingText.text = "Refreshing token silently"
self.loggingText.text = "Refreshed Access token is \(self.accessToken)"
}
마지막으로 SignUp / SignIn (초기 인증 호출)에 사용 된 권한 / 정책을 AcquireTokenSilent에 추가하려고했는데이 오류가 발생합니다.
"캐시에서이 인수와 일치하는 토큰이 없습니다."라는 메시지가 나타납니다. (세 번째 링크를 게시 할 수 없습니다)
let application = try MSALPublicClientApplication.init(clientId: kClientID, authority: kAuthority)
let thisUser = userFromAuth
application.acquireTokenSilent(forScopes: kScopes, user: thisUser, authority: kAuthority) { (result, error) in
if error == nil {
self.accessToken = (result?.accessToken)!
self.loggingText.text = "Refreshing token silently"
self.loggingText.text = "Refreshed Access token is \(self.accessToken)"
}
Android 샘플 앱에서 토큰 새로 고침 기능을 테스트했으며 토큰을 성공적으로 새로 고칠 수 있으므로 문제가 B2C 어디에도 없다고 생각합니다. 또한 MSAL 라이브러리가 Android 및 Obj-C 예제에서 사용되는 AppAuth 라이브러리와 다르게 새로 고침을 처리한다는 것을 읽었으므로 누락 된 것이 있는지 확실하지 않습니다.
무엇이 잘못 될 수 있는지에 대한 통찰력이 있으면 좋을 것입니다!
잘 됐어. useridentifier는 모두 소문자로 된 정책 이름 (예 : 56d56ec5-96a9-4c23-9717-4ae5d86f967c-b2c_1_policy)과 함께 반환되므로 정책에 대문자가있는 경우 사용자 (및 토큰)를 찾을 수 없습니다.
getUserByPolicy 메서드의 forPolicy 문자열 끝에 .lowercased ()를 추가하여 수정했습니다.
for user in withUsers {
if (user.userIdentifier().components(separatedBy: ".")[0].hasSuffix(forPolicy.lowercased())) {
return user
}
}
또한 최신 버전의 Xcode (8.3.3)를 사용해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다