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

查看:363
本文介绍了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.

这是我到目前为止所做的:

Here´s what I done so far:

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.

这是您通常会在登录页面中输入的代码,第一个用于检查我们是否收到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是包含以下内容的URL:用户在最后添加了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天全站免登陆