Java
对应的官方页面地址
入门
1、将我们的包的依赖项添加到您的 pom.xml 中:
<dependency>
<groupId>com.bitwarden</groupId>
<artifactId>passwordless</artifactId>
<version>1.0.5</version>
</dependency>示例
此 Java 实现与 Java 8 及更高版本兼容。注册函数可能看起来像这样:
创建 PasswordlessClient 实例:
PasswordlessClient 实例:import com.bitwarden.passwordless.*;
import java.io.*;
public class PasswordlessJavaSdkExample implements Closeable {
private final PasswordlessClient client;
public PasswordlessClientExample() {
PasswordlessOptions options = PasswordlessOptions.builder()
.apiSecret("your_api_secret")
.build();
client = PasswordlessClientBuilder.create(options)
.build();
}
@Override
public void close() throws IOException {
client.close();
}
}注意:使用带有 close 方法的 PasswordlessClient 后,需要关闭底层 http 客户端资源。
注册通行密钥
验证用户
自定义
通过向 apiSecret 提供您的应用程序的私有 API 密钥来自定义 PasswordlessOptions。如果您喜欢自行托管,也可以更改 apiUrl。
通过提供 httpClient CloseableHttpClient 实例和 objectMapper ObjectMapper 来自定义PasswordlessClientBuilder。
示例
有关使用此库的 Spring Boot 3 应用程序,请参阅 Passwordless Java 示例。
最后更新于