调用Azure SQL数据库REST API会出现错误:不支持Basic的身份验证方案 [英] Calling Azure SQL Database REST API gives the error: The authentication scheme of Basic is not supported

查看:57
本文介绍了调用Azure SQL数据库REST API会出现错误:不支持Basic的身份验证方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 WPF Core 客户端应用程序的以下代码中,我正在尝试使用此

In the following code of my WPF Core client app , I am trying to use this Azure SQL Database REST API to delete a database in my Azure subscription. But I am getting the error shown below:

问题:我可能遗失的东西以及如何解决该问题?

Question: What I may be missing, and how can we resolve the issue?

备注:我在此处找到了一个类似的示例,但我不确定为什么我的代码无法正常工作.当我从笔记本电脑上的 SSMS-2019 连接到相同的Azure SQL Db时,相同的用户名(具有SQL Admin访问权限)和密码可以正常工作.

Remark: I found a similar example here, and I'm not sure why my code is not working. The same user name (with SQL Admin access) and password works fine when I connect to the same Azure SQL Db from SSMS - 2019 on my laptop.

代码:

const string uri = "https://management.azure.com/subscriptions/a7686c7e8f-211d-45e5-8f5e-525015b1c881/resourceGroups/myResourceGroup/providers/Microsoft.Sql/servers/mysqlserver/databases/AdventureWorksLT2019?api-version=2019-06-01-preview";

using (var client = new HttpClient())
{
    var byteArray = Encoding.ASCII.GetBytes("mySQLAdminUserName:MySQLAdminPassword");
    var header = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
    client.DefaultRequestHeaders.Authorization = header;

    var result = await client.DeleteAsync(uri);
    System.Diagnostics.Debug.Write(result.Content.ReadAsStringAsync().Result);
}

error ="invalid_token",error_description =不支持Basic的身份验证方案."

error="invalid_token", error_description="The authentication scheme of Basic is not supported."

错误详细信息:

{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: no-cache
  Pragma: no-cache
  WWW-Authenticate: Bearer authorization_uri="https://login.windows.net/96eafd5a-8ce3-4c0c-981c-8eac1f59ab96", error="invalid_token", error_description="The authentication scheme of Basic is not supported."
  x-ms-failure-cause: gateway
  x-ms-request-id: 43f41f28-5a18-42b7-8e70-d6599996ce0e
  x-ms-correlation-request-id: 43f41f28-5a18-42b7-8e70-d6599996ce0e
  x-ms-routing-request-id: EASTUS:20201010T035452Z:43f41f28-5a18-42b7-8e70-d6599996ce0e
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  X-Content-Type-Options: nosniff
  Date: Sat, 10 Oct 2020 03:54:51 GMT
  Connection: close
  Content-Type: application/json; charset=utf-8
  Expires: -1
  Content-Length: 150
}}

推荐答案

我认为您可能会混淆身份验证.

I think you may be mixing up the authentication.

使用SSMS连接时,您正在连接到数据库并在数据库上进行身份验证.

When connecting using SSMS, you are connecting to the database and authenticating at the database.

要删除数据库,您需要使用具有足够权限删除Azure SQL数据库的Azure AD帐户连接到Azure租户.

To delete the database you need to be connecting to your Azure tenant with an Azure AD account that has sufficient rights to delete an Azure SQL Database.

尝试使用您的Azure帐户进行身份验证.

Try authenticating with your Azure account.

这篇关于调用Azure SQL数据库REST API会出现错误:不支持Basic的身份验证方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆