steam login using openID in android
I think i discovered some sort of a workaround i guess.
The steam openid can be used with a url request like this:
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/
where REALM_PARAM is the website that will appear on the login screen, Also the user will be redirected to that website after authentication is complete, it doesn't have to actually exist. All you had to do after that is parse the new url for the user id.
So i used something like this
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);
}
}
Use pure HTML in a form tag
This way you can cover Android devices AND everything that speaks HTML. This achieves the login as outlined in the official 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>
- The user will click the button in this form on your site and will be redireced to the Steam community login page.
- The user can then log into their Steam account on the Steam community pages.
- With
YourDomainUrlToReturnTo
you specify where the user retuns to your site after successful login via Steam. - Steam will provide the Steam ID in the browser's location object.
- With that Steam ID you can fetch user info via the Steam Web API.