在android中使用openID登录steam

Lim*_*mBo 18 openid android steam

我刚接触android开发.我的项目是使用steam public API创建一个应用程序,但我无法弄清楚如何允许用户使用steam帐户登录.

蒸汽的Web API文档指出我应该使用OpenID的,所以我搜索了很多寻找在Andorid的应用程序实现OpenID的一个例子,但是是我发现的唯一例子,这是行不通的,web视图偏偏空白.

我只是希望用户点击登录按钮,该按钮会激活用户可以登录的webView,然后返回他的蒸汽ID.

所以我的问题是

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

Lim*_*mBo 15

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

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/
Run Code Online (Sandbox Code Playgroud)

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

            }
        }
Run Code Online (Sandbox Code Playgroud)