Steam Login Authentication C#

﹥>﹥吖頭↗ 提交于 2019-12-04 11:45:08

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

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.

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.

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.

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();
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!