首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >检索App服务的访问令牌

检索App服务的访问令牌
EN

Stack Overflow用户
提问于 2018-08-01 16:32:43
回答 2查看 1.5K关注 0票数 0

目前,我已经在Visual中创建了一个用于MS团队的Bot。我需要一种方法,以检索用户的机器人在MS团队,当他们已经使用它,如电子邮件地址,全名等。此Bot作为应用程序服务托管在Azure中。我遵循了这个链接https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-auth-aad并在我的应用程序服务上配置了Azure Active身份验证。下面的代码尝试从Azure检索访问令牌,然后我将使用该令牌从https://graph.microsoft.com/v1.0/me获取信息。

代码语言:javascript
运行
复制
static async Task<AuthenticationResult> GetS2SAccessToken(string authority, string resource, string clientId, string clientSecret)
{
    var clientCredential = new ClientCredential(clientId, clientSecret);
    AuthenticationContext context = new AuthenticationContext(authority, false);
    AuthenticationResult authenticationResult = await context.AcquireTokenAsync(
        resource,  // the resource (app) we are going to access with the token
        clientCredential);  // the client credentials
    return authenticationResult;
}

我从其他地方获取了这段代码,但我遇到的问题是,我看不到Azure Active Directory应用程序的客户端秘密,也不知道什么是“授权”。这是我第一次使用这样的东西,所以我很感激这方面的任何指点或提示。

代码语言:javascript
运行
复制
static string authority = "https://login.microsoftonline.com/common";
static string clientId = "my_azure-ad_app_id";
static string resource = "https://<app_name>.azurewebsites.net/";
static string clientSecret = "azure-ad_app_secret";

static public async Task<AuthenticationResult> GetS2SAccessTokenForProdMSAAsync()
{
    return await GetS2SAccessToken(authority, resource, clientId, clientSecret);
}

static async Task<AuthenticationResult> GetS2SAccessToken(string authority, string resource, string clientId, string clientSecret)
{
    var clientCredential = new ClientCredential(clientId, clientSecret);
    AuthenticationContext context = new AuthenticationContext(authority, false);
    AuthenticationResult authenticationResult = await context.AcquireTokenAsync(
        resource,  // the resource (app) we are going to access with the token
        clientCredential);  // the client credentials
    return authenticationResult;
}

到目前为止,这是我要检索访问令牌的代码,但它没有返回任何内容。

EN

Stack Overflow用户

发布于 2018-08-02 03:23:48

补充朱纳斯的答案。你可以试试这个参考文档

客户端Id:

客户端秘密:

注:客户端秘密仅在创建时可见。之后,它就不会再出现了。所以,确保你第一次复制自己。

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51638251

复制
相关文章

相似问题

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