let credentialsManager = CredentialsManager(authentication: Auth0.authentication())Auth0 .webAuth() .scope("openid profile offline_access") .start { result in switch result { case .success(let credentials): // 資格情報をCredentials Managerに渡す credentialsManager.store(credentials: credentials) case .failure(let error): // エラーを処理する }}
credentialsManager.credentials { result in switch result { case .success(let credentials): // 有効な資格情報です。`idToken`、`accessToken` などのトークンプロパティにアクセスできます case .failure(let error): // エラーを処理し、ログインページを表示します }}
token の有効期限が切れている場合でも、ユーザーの資格情報の更新方法はまったく同じです。Credentials Manager は資格情報を自動的に更新し、更新後の資格情報を Keychain に保存したうえで、資格情報またはエラーのいずれかを含む Result を返します。