Trying to access Azure MySQL DB via api, but recive “AuthorizationFailed” error

novaspark 26 Reputation points
2021-08-05T09:08:15.32+00:00

request:
https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroups}}/providers/Microsoft.DBforMySQL/servers/{{dbhost}}/databases/{{db}}?api-version=2017-12-01

response:
{
"error": {
"code": "AuthorizationFailed",
"message": "The client 'c3ac6bdd-98c1-481e-a9cf-1b1622cb6d7c' with object id 'c3ac6bdd-98c1-481e-a9cf-1b1622cb6d7c' does not have authorization to perform action 'Microsoft.DBforMySQL/servers/databases/read' over scope '/subscriptions/91e9b0e1-a770-479d-be45-3d1e32581c09/resourceGroups/lfss-azure-eastus-rg/providers/Microsoft.DBforMySQL/servers/lf-test.mysql.database.azure.com/databases/lftdb' or the scope is invalid. If access was recently granted, please refresh your credentials."
}
}

send request vis postman and i can access azure-mysqldb via database management software.

before send request i send a Authorise Request
request:
【https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={{clientId}}&response_type=code&redirect_uri=http://localhost/myapp/&response_mode=query&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read&state=12345
response code is 200 and got a bearerToken】

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
864 questions
{count} votes

Accepted answer
  1. Oury Ba-MSFT 19,886 Reputation points Microsoft Employee
    2021-08-25T00:04:04.187+00:00

    Hi @novaspark
    Could you please generate the access token and then used it in request header. Use the command in the link I shared below
    command to get token az account get-access-token
    https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az_account_get_access_token

    Let us know if you the error occurred again

    Regards,
    Oury

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.