配置了一个回复地址后,应用程序没有注册回复地址
No reply address is registered for the application when there is one configured
我正在制作一个 WPF 应用程序,它必须从 Azure Key Vault 获取密钥,但我总是出现以下错误:
AADSTS500113: No reply address is registered for the application.
这是我使用的代码:
public class KeyProvider
{
public string BaseUrl => "https://my-key-vault.vault.azure.net";
public Uri RedirectUri => new Uri("urn:ietf:wg:oauth:2.0:oob");
public KeyVaultClient KeyVaultClient { get; private set; }
public KeyProvider()
{
KeyVaultClient = new KeyVaultClient(GetAccessToken);
}
public async Task<string> GetSecretAsync(string key)
{
SecretBundle secret = await KeyVaultClient.GetSecretAsync(BaseUrl, key);
return secret.Value;
}
private async Task<string> GetAccessToken(string azureTenantId, string clientId, string redirectUri)
{
AuthenticationContext context = new AuthenticationContext(azureTenantId);
AuthenticationResult tokenResult = await context.AcquireTokenAsync("https://vault.azure.net", clientId, RedirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
return tokenResult.AccessToken;
}
}
当我调试 GetAccessToken
时,我看到 redirectUri
(方法的参数) 是一个空字符串。
这是我在 Azure 门户中的配置。
我错过了什么吗?
在您的代码中,重定向 uri 是 http。但是在您的应用程序中,它是 https。请尝试将它们设置为相同的。
更新:
权限:
平台:
在 Key Vault 中为用户添加访问策略。
代码:
class Program
{
public static string clientId = "d4c9b2ed-****-****-****-30a787f7c928";
public static string redirectUri = "https://localhost/";
public static string baseUrl = "https://jackkv.vault.azure.net/";
public static async Task<string> AuthenticationCallback(string authority, string resource, string scope)
{
var result = await new AuthenticationContext(authority).AcquireTokenAsync(resource, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.RefreshSession));
return result.AccessToken;
}
static void Main(string[] args)
{
Console.ReadLine();
KeyVaultClient kvc = new KeyVaultClient(AuthenticationCallback);
var secret = kvc.GetSecretAsync(baseUrl, "testSecret").Result;
Console.WriteLine(secret.Value);
Console.ReadLine();
}
}
结果:
我发现了这个错误。我基于 。这是我的代码:
public string ClientID => "01234567-89ab-cdef-0123-456789abcdef";
// skipped some lines...
private async Task<string> GetAccessToken(string authority, string resource, string redirectUri)
{
AuthenticationContext context = new AuthenticationContext(authority);
AuthenticationResult tokenResult = await context.AcquireTokenAsync(resource, ClientID, RedirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
return tokenResult.AccessToken;
}
我正在制作一个 WPF 应用程序,它必须从 Azure Key Vault 获取密钥,但我总是出现以下错误:
AADSTS500113: No reply address is registered for the application.
这是我使用的代码:
public class KeyProvider
{
public string BaseUrl => "https://my-key-vault.vault.azure.net";
public Uri RedirectUri => new Uri("urn:ietf:wg:oauth:2.0:oob");
public KeyVaultClient KeyVaultClient { get; private set; }
public KeyProvider()
{
KeyVaultClient = new KeyVaultClient(GetAccessToken);
}
public async Task<string> GetSecretAsync(string key)
{
SecretBundle secret = await KeyVaultClient.GetSecretAsync(BaseUrl, key);
return secret.Value;
}
private async Task<string> GetAccessToken(string azureTenantId, string clientId, string redirectUri)
{
AuthenticationContext context = new AuthenticationContext(azureTenantId);
AuthenticationResult tokenResult = await context.AcquireTokenAsync("https://vault.azure.net", clientId, RedirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
return tokenResult.AccessToken;
}
}
当我调试 GetAccessToken
时,我看到 redirectUri
(方法的参数) 是一个空字符串。
这是我在 Azure 门户中的配置。
我错过了什么吗?
在您的代码中,重定向 uri 是 http。但是在您的应用程序中,它是 https。请尝试将它们设置为相同的。
更新:
权限:
平台:
在 Key Vault 中为用户添加访问策略。
代码:
class Program
{
public static string clientId = "d4c9b2ed-****-****-****-30a787f7c928";
public static string redirectUri = "https://localhost/";
public static string baseUrl = "https://jackkv.vault.azure.net/";
public static async Task<string> AuthenticationCallback(string authority, string resource, string scope)
{
var result = await new AuthenticationContext(authority).AcquireTokenAsync(resource, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.RefreshSession));
return result.AccessToken;
}
static void Main(string[] args)
{
Console.ReadLine();
KeyVaultClient kvc = new KeyVaultClient(AuthenticationCallback);
var secret = kvc.GetSecretAsync(baseUrl, "testSecret").Result;
Console.WriteLine(secret.Value);
Console.ReadLine();
}
}
结果:
我发现了这个错误。我基于
public string ClientID => "01234567-89ab-cdef-0123-456789abcdef";
// skipped some lines...
private async Task<string> GetAccessToken(string authority, string resource, string redirectUri)
{
AuthenticationContext context = new AuthenticationContext(authority);
AuthenticationResult tokenResult = await context.AcquireTokenAsync(resource, ClientID, RedirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
return tokenResult.AccessToken;
}