Iam new to android development. my project is to make an application using steam public API but i couldn't figure out how to allow the user to login using steam account.
Steam's web API documentation states that i should use openID, So i searched alot to find an example implementing openID in an andorid app, but this is the only example i found and it doesn't work, the webView just turns out blank.
i just want the user to click on a login button which fires a webView where he user can login and then get his steam ID back.
so my question is
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);
}
}