首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SteamAuth从startup.auth到视图ASP.NET的变量

SteamAuth从startup.auth到视图ASP.NET的变量
EN

Stack Overflow用户
提问于 2015-11-02 10:43:47
回答 1查看 1.4K关注 0票数 1

我想从蒸汽中得到侧写信息。所以首先我修正了我可以通过蒸汽登录,我使用了下面的教程:http://www.oauthforaspnet.com/providers/steam/

但是,现在我希望从登录的用户那里获得蒸汽配置文件id,这样我就可以使用来自蒸汽API的JSON从用户那里获取信息。

https://steamcommunity.com/profiles/(this

我希望有人能帮我,我已经找了好几个小时了,但没有结果。

代码语言:javascript
复制
var options = new SteamAuthenticationOptions {
ApplicationKey = "Your API Key",
Provider = new OpenIDAuthenticationProvider // Steam is based on OpenID
{
    OnAuthenticated = async context =>
    {
        // Retrieve the user's identity with info like username and steam id in Claims property
        var identity = context.Identity;
    }
}}; app.UseSteamAuthentication(options);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-07 22:50:51

不久前,我们发现了答案:

1.)在这里插入教程中的密钥:

代码语言:javascript
复制
var options = new SteamAuthenticationOptions
{
    ApplicationKey = "Your API Key",
    Provider = new OpenIDAuthenticationProvider // Steam is based on OpenID
    {
        OnAuthenticated = async context =>
        {
            // Retrieve the user's identity with info like username and steam id in Claims property
            var identity = context.Identity;
        }
    }
};
app.UseSteamAuthentication(options);

2.)我们发现蒸汽在数据库表中保存了一个名为'AspNetUserLogins‘的用户蒸汽id,该表中的提供键是一个由更多的部分组成的url。例如:

代码语言:javascript
复制
http://steamcommunity.com/openid/id/here-users-steamid

我们只需要用户斯泰姆,所以我们将在步骤3中分割。

3.)制作一个控制器,例如: SteamController。在这里,我们将添加一个公共字符串:

代码语言:javascript
复制
public string GetSteamID()
    {
        var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new Steam.Models.ApplicationDbContext()));
        var CurrentUser = manager.FindById(User.Identity.GetUserId());
        if (User.Identity.Name != "")
        {
            string url = CurrentUser.Logins.First().ProviderKey;
            ViewBag.steamid = url.Split('/')[5]; //here we going to split the providerkey so we get the right part
        }
        else
        {
            ViewBag.steamid = "";
        }

        return ViewBag.steamid;
    }
  1. )现在我们可以添加一些东西,比如说我们要添加配置文件信息。转到您的SteamController并添加: HttpGet public ContentResult GetProfile() { string url = string.Format("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=addyourkeyhere&steamids={0}",this.GetSteamID()“);string result = null;使用(var client =新WebClient()) {string.Format= client.DownloadString(url);}返回内容(结果,"application/json");}

请注意,您必须在url中添加步骤1中的蒸汽密钥。

  1. )创建一个名为: profile.js的脚本。在这里,我们将添加我们的个人资料。

代码语言:javascript
复制
function profilepic() {
    $.ajax({
        url: 'http://localhost:3365/steam/GetProfile',
        dataType: 'json',
        success: function (data) {
            $.each(data.response.players, function (key, value) {
                if ($('.profile')) {
                    $('.profile').append("<img src='" + value.avatar + "'> <span>" + value.personaname + "</span>")
                }
                if ($('.profile1')) {
                    $('.profile1').append("<img src='" + value.avatarfull + "'>")
                }
                if ($('.username')) {
                    $('.username').append(value.personaname)
                }
                
                console.log(value)
            });
        }, error: function (httpReq, status, exception) {
            console.log(status + " " + exception);
        }
    });
}

6.)现在我们必须完成最后一步,用类创建一个视图,例如:

代码语言:javascript
复制
<div class="userprofile">
    <span class="profile1"></span>
    <div class="userdescription">
        <h2 class="username"></h2>
    </div>
</div>
  1. 我希望这将帮助一些人,如果有更多的问题,可以随意提问!
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33475737

复制
相关文章

相似问题

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