我是android开发的新手。我的项目是使用steam公共API制作一个应用程序,但我不知道如何允许用户使用steam帐户登录。
Steam的web文档指出我应该使用openID,所以我搜索了很多东西来寻找一个在andorid应用中实现openID的例子,但是this是我找到的唯一一个例子,它不起作用,webView就是一片空白。
我只想让用户点击一个登录按钮,它会触发一个webView,用户可以在那里登录,然后拿回他的steam ID。
所以我的问题是
发布于 2015-06-16 21:57:59
我想我发现了某种变通方法。
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是将出现在登录屏幕上的网站,而且用户将在身份验证完成后被重定向至该网站,该网站不必实际存在。
所以我用了这样的东西
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);
}
}
发布于 2020-01-28 05:43:48
在表单标记中使用纯HTML
通过这种方式,您可以覆盖Android设备和所有使用HTML的内容。这就实现了官方Steam documentation中列出的登录。
<form action="https://steamcommunity.com/openid/login" method="post">
<input type="hidden" name="openid.identity"
value="http://specs.openid.net/auth/2.0/identifier_select" />
<input type="hidden" name="openid.claimed_id"
value="http://specs.openid.net/auth/2.0/identifier_select" />
<input type="hidden" name="openid.ns" value="http://specs.openid.net/auth/2.0" />
<input type="hidden" name="openid.mode" value="checkid_setup" />
<input type="hidden" name="openid.realm" value="https:\\yourOpenIdRealm.com" />
<input type="hidden" name="openid.return_to" value="https:\\YourDomainUrlToReturnTo.com" />
<Button type="submit">Log in through Steam</Button>
</form>
YourDomainUrlToReturnTo
的获取
发布于 2019-12-07 14:05:44
我更正了@LibBo的代码。有一些语法错误。还将ActionBarActivity
更新为AppCompatActivity
。
public class SteamActivity extends AppCompatActivity {
// 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);
setContentView(R.layout.activity_steam);
final WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
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);
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
}
}
});
}
}
https://stackoverflow.com/questions/29873941
复制相似问题