必须配置 ICredentialRepository 服务才能使用此功能

ICredentialRepository service must be configured in order to use this feature

来自 https://github.com/wstrange/GoogleAuth

为用户设置凭据时:

GoogleAuthenticator gAuth = new GoogleAuthenticator(); final GoogleAuthenticatorKey key = gAuth.createCredentials("daryll123");

发生异常:

java.lang.UnsupportedOperationException: An instance of the com.warrenstrange.googleauth.ICredentialRepository service must be configured in order to use this feature.

如何使用 ICredentialRepository 进行配置才能工作? 它指出 Java ServiceLoader API。不知道是怎么回事。

您必须在某处实现 ICredentialRepository 接口方法,并使用

将 class 设置为您的 gAuth 变量上的凭据存储库
setCredentialRepository()

如果您在当前 class 上实现这些方法,您可以使用

gAuth.setCredentialRepository(this)

接口方法是

String getSecretKey(String userName);

void saveUserCredentials(String userName,
                         String secretKey,
                         int validationCode,
                         List<Integer> scratchCodes);

该错误令人困惑,因为它没有给出您的凭据存储库设置不正确的上下文。希望这对您有所帮助!