繁体   English   中英

我可以使用Stormpath Java SDK在strompath中验证用户帐户吗?

[英]Can I authenticate a user account in strompath using Stormpath Java SDK?

我想验证已经从Web管理控制台创建的用户帐户,以便我可以检索用户帐户的数据。

我已经看过有关身份验证方案的文档,但没有找到任何代码段。

以下是使用Stormpath对现有用户进行身份验证的示例:

// Instantiate a builder for your client and set required properties
ClientBuilder builder = Clients.builder();    

// Build the client instance that you will use throughout your application code
Client client = builder.build();

Tenant tenant = client.getCurrentTenant();
ApplicationList applications = tenant.getApplications(
        Applications.where(Applications.name().eqIgnoreCase("My Application"))
);

Application application = applications.iterator().next();


//Capture the username and password, such as via an SSL-encrypted web HTML form. 
//We'll just simulate a form lookup and use the values we used above:
String usernameOrEmail = "tk421@stormpath.com";
String rawPassword = "Changeme1";

//Create an authentication request using the credentials
AuthenticationRequest request = new UsernamePasswordRequest(usernameOrEmail, rawPassword);

//Now let's authenticate the account with the application:
try {
    AuthenticationResult result = application.authenticateAccount(request);
    Account account = result.getAccount();
} catch (ResourceException ex) {
    System.out.println(ex.getStatus() + " " + ex.getMessage());
}

您可以在此处查看有关Stormpath Java SDK的更多信息

完全披露:我为Stormpath工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM