Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

steam login using openID in android

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

  1. Is there a way to implement openID login in android?
  2. If not, is there anyway to allow the user to login steam?
like image 768
LimBo Avatar asked Apr 26 '15 04:04

LimBo


2 Answers

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);

            }
        }
like image 121
LimBo Avatar answered Oct 14 '22 00:10

LimBo


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.
like image 30
EliteRaceElephant Avatar answered Oct 14 '22 00:10

EliteRaceElephant