认证
16

项目认证

下面的例子演示了如何用项目的ID和秘密同步验证服务器客户端。

Java
import com.enjin.sdk.*;

public class ExampleServer {

private TrustedPlatformClient client;

public ExampleServer() {
this.client = new TrustedPlatformClientBuilder().baseUrl(TrustedPlatformClientBuilder.KOVAN)
.build();
}

public boolean authApp(int appId, String appSecret) {
this.client.authAppSync(appId, appSecret);

return client.isAuthenticated();
}
}

玩家认证

一旦服务器客户端通过了认证,你就可以得到一个玩家访问令牌,如下图所示。然后玩家访问令牌应该被转发给玩家客户端。

Java
import com.enjin.sdk.*;
import com.enjin.sdk.graphql.GraphQLResponse;
import com.enjin.sdk.http.HttpResponse;
import com.enjin.sdk.models.AccessToken;
import com.enjin.sdk.models.user.*;

public class ExampleServer {

private TrustedPlatformClient client;

public ExampleServer() {
this.client = new TrustedPlatformClientBuilder().baseUrl(TrustedPlatformClientBuilder.KOVAN)
.build();
}

public void authPlayer(String id) {
AuthPlayer input = new AuthPlayer().id(id);
HttpResponse<>> httpResponse = client.getUserService().authUserSync(input);

if (!httpResponse.isEmpty()) {
GraphQLResponse graphQLResponse = httpResponse.body();

if (!graphQLResponse.hasErrors()) {
AccessToken accessToken = graphQLResponse.getData();
}
}
}
}
上一页
接下来
本页