gpt4 book ai didi

azure - Azure 上 API 应用程序中的 Microsoft 帐户身份验证

转载 作者:行者123 更新时间:2023-12-02 07:12:57 37 4
gpt4 key购买 nike

我希望完成的是通过 Microsoft 帐户身份验证提供程序连接到 Visual Studio Team Services。我一直在关注此处的文档 ( https://github.com/Azure/azure-content/blob/master/articles/app-service-api/app-service-api-dotnet-connect-to-saas.md ),但在实现方面遇到了一些问题。

他们使用 Microsoft.Azure.AppService.ApiApps.Service 包从 api 网关获取 token

// Retrieve the token from the gateway
var runtime = Runtime.FromAppSettings(Request);
var dropboxTokenResult = await runtime.CurrentUser.GetRawTokenAsync("dropbox");

但是当我发布我的 web 应用程序时,在尝试创建运行时对象时出现 500 错误,远程调试器实际上就在下面的行中死掉了,我什至在 api 的流日志界面中看不到任何日志来提供更多信息有关错误的信息。

var runtime = Runtime.FromAppSettings(Request);

关于如何获取 token 有什么想法吗?

使用 Web API 实现 microsoftaccount 身份验证的文档有点稀缺,是否有任何对你们有帮助的示例或文档的链接?

此外,apiapp.json 文件真的有必要吗?他们在示例中创建了一个,但通过 Azure Blade 进行身份验证设置似乎工作正常,并且将 apiapp.json 文件保留在 api 之外似乎无论如何都不重要。最后,我希望我的 Web api 能够通过微软帐户维护身份验证,无论它移动到哪里,所以我认为在某个地方会有一些我需要指定的设置,但也无法真正将其组合在一起。

最佳答案

您似乎正在使用旧模型来构建 API 应用程序(涉及网关),但该模型已被弃用。我相信它仍然受支持,但构建 API 应用程序的官方方式已经改变,您可能会发现它使用起来更简单。更多信息可以在这里找到:https://azure.microsoft.com/en-us/documentation/articles/app-service-api-whats-changed/

利用 Microsoft 帐户身份验证的文档位于:https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-microsoft-authentication/

完成设置后,您可以通过几种不同的方式获取 token 。您可以将其作为入站 HTTP header (x-ms-token-microsoftaccount-access-token) 找到,也可以使用 App Service Server SDK获得它:类似于:

var creds = await this.User.GetAppServiceIdentityAsync<MicrosoftAccountCredentials>(this.Request);
string accessToken = creds.AccessToken;

关于azure - Azure 上 API 应用程序中的 Microsoft 帐户身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35298993/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com