Steam 登录认证 C# [英] Steam Login Authentication C#

查看:42
本文介绍了Steam 登录认证 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 DotNetOpenAuth 使 Steam 登录为我的网站工作.

Im trying to make steam login work for my website with DotNetOpenAuth.

但是查看文档中的示例并没有让我知道如何使其工作.

But looking through the examples in the documentation doesn't give me any idea how to make it work.

这是我目前所做的:

1) 将 dotnetopenauth 参考文件添加到 \bin 和配置中

1) Added the dotnetopenauth reference files to \bin and to the configuration

2) 在数据库中为我从 DotNetOpenAuth 得到的响应添加了一个唯一的用户字段.

2) Added a unique user field in the database for the response i get back from DotNetOpenAuth.

所以这是我的问题

如何使用 DotNetOpenAuth 检索 Steam id?

How can i retrive the steam id with DotNetOpenAuth?

我发现了一些用 php 完成的例子:http://forums.steampowered.com/forums/showthread.php?t=1430511

I found some examples done in php: http://forums.steampowered.com/forums/showthread.php?t=1430511

推荐答案

当您包含正确的 DotNetOpenAuth 时,应该这样做.

This should do it, when you include the correct DotNetOpenAuth.

这是您通常会放入登录页面的代码,第一个 if 检查我们是否收到来自 Steam 的响应并处理响应.

This is code you would typically put in your Login page, the first if checks whether we have a response from Steam and deals with the response.

else 部分设置请求并将用户重定向到 Steam - 一旦用户登录 Steam,steam 将重定向回此页面.

The else part makes sets up the request and redirects the user to Steam - steam will then redirect back to this page once the user has logged in on steam.

与其他开放身份验证提供商不同,steam 不会通过随请求发送声明请求来提供其他用户信息(电子邮件等)——它只会在响应中提供一个 URL.ClaimedIdentifier 是一个包含最后是用户的 Steam id.

Unlike other open auth providers, steam does not provide other user information (email, etc...) by sending a claims request with the request - it will only provide a URL in the response.ClaimedIdentifier which is a URL containing the users steam id at the end.

如果需要,您必须进行字符串操作才能仅获取 ID.

You will have to do the string manipulation to only get the ID if you want.

protected void Page_Load(object sender, EventArgs e)
{
    var openid = new OpenIdRelyingParty();
    var response = openid.GetResponse();

    if (response != null)
    {
        switch (response.Status)
        {
            case AuthenticationStatus.Authenticated:
                // do success
                var responseURI = response.ClaimedIdentifier.ToString();
                //"http://steamcommunity.com/openid/id/76561197969877387"
                // last part is steam user id
                break;

            case AuthenticationStatus.Canceled:
            case AuthenticationStatus.Failed:
                // do fail
                break;
        }
    }
    else
    {
        using (OpenIdRelyingParty openidd = new OpenIdRelyingParty())
        {
            IAuthenticationRequest request = openidd.CreateRequest("http://steamcommunity.com/openid");
            request.RedirectToProvider();
        }
    }
}

这篇关于Steam 登录认证 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆