gpt4 book ai didi

android - 在android中使用openID登录steam

转载 作者:IT老高 更新时间:2023-10-28 23:34:12 28 4
gpt4 key购买 nike

我是 android 开发的新手。我的项目是使用 Steam 公共(public) API 制作应用程序,但我不知道如何允许用户使用 Steam 帐户登录。

Steam 的 web API 文档声明我应该使用 openID,所以我搜索了很多以找到一个在 anorid 应用程序中实现 openID 的示例,但是 this是我找到的唯一示例,但它不起作用,webView 只是空白。

我只想让用户点击一个登录按钮,该按钮会触发一个 webView,用户可以在其中登录,然后取回他的 Steam ID。

所以我的问题是

  1. 有没有办法在android中实现openID登录?
  2. 如果没有,是否有允许用户登录steam?

最佳答案

我想我发现了某种解决方法。

steam openid 可以与这样的 url 请求一起使用:

https://steamcommunity.com/openid/login?
openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&
openid.identity=http://specs.openid.net/auth/2.0/identifier_select&
openid.mode=checkid_setup&
openid.ns=http://specs.openid.net/auth/2.0&
openid.realm=https://REALM_PARAM&
openid.return_to=https://REALM_PARAM/signin/

其中 REALM_PARAM 是将出现在登录屏幕上的网站,并且用户将在身份验证完成后被重定向到该网站,它不必实际存在。之后您所要做的就是解析用户 ID 的新 url。

所以我用了这样的东西

public class LoginActivity extends ActionBarActivity {

// The string will appear to the user in the login screen
// you can put your app's name
final String REALM_PARAM = "YourAppName";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);

final Activity activity = this;

webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {

//checks the url being loaded
setTitle(url);
Uri Url = Uri.parse(url);

if(Url.getAuthority().equals(REALM_PARAM.toLowerCase())){
// That means that authentication is finished and the url contains user's id.
webView.stopLoading();

// Extracts user id.
Uri userAccountUrl = Uri.parse(Url.getQueryParameter("openid.identity"));
String userId = userAccountUrl.getLastPathSegment();

// Do whatever you want with the user's steam id

});
setContentView(webView);

// Constructing openid url request
String url = "https://steamcommunity.com/openid/login?" +
"openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&" +
"openid.identity=http://specs.openid.net/auth/2.0/identifier_select&" +
"openid.mode=checkid_setup&" +
"openid.ns=http://specs.openid.net/auth/2.0&" +
"openid.realm=https://" + REALM_PARAM + "&" +
"openid.return_to=https://" + REALM_PARAM + "/signin/";

webView.loadUrl(url);

}
}

关于android - 在android中使用openID登录steam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29873941/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com