首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在安卓系统中使用openID进行steam登录

在安卓系统中使用openID进行steam登录
EN

Stack Overflow用户
提问于 2015-04-26 12:58:50
回答 3查看 4.6K关注 0票数 19

我是android开发的新手。我的项目是使用steam公共API制作一个应用程序,但我不知道如何允许用户使用steam帐户登录。

Steam的web文档指出我应该使用openID,所以我搜索了很多东西来寻找一个在andorid应用中实现openID的例子,但是this是我找到的唯一一个例子,它不起作用,webView就是一片空白。

我只想让用户点击一个登录按钮,它会触发一个webView,用户可以在那里登录,然后拿回他的steam ID。

所以我的问题是

  1. 有没有办法在安卓上实现openID登录?
  2. 如果没有,有没有办法允许用户登录steam?
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-06-16 21:57:59

我想我发现了某种变通方法。

steam openid可以与如下的url请求一起使用:

代码语言:javascript
复制
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是将出现在登录屏幕上的网站,而且用户将在身份验证完成后被重定向至该网站,该网站不必实际存在。

所以我用了这样的东西

代码语言:javascript
复制
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);

            }
        }
票数 17
EN

Stack Overflow用户

发布于 2020-01-28 05:43:48

表单标记中使用纯HTML

通过这种方式,您可以覆盖Android设备和所有使用HTML的内容。这就实现了官方Steam documentation中列出的登录。

代码语言:javascript
复制
    <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
  • 您可以指定用户通过Steam成功登录后返回到您的站点的位置。
  • Steam将在浏览器的location object中提供Steam ID。使用该蒸汽ID,您可以通过Steam Web API.

获取

  • 的用户信息
票数 1
EN

Stack Overflow用户

发布于 2019-12-07 14:05:44

我更正了@LibBo的代码。有一些语法错误。还将ActionBarActivity更新为AppCompatActivity

代码语言:javascript
复制
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

                }
            }
        });
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29873941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档