Microsoft.SCIM.WebHostSample failled autorize in azure Ad

75 Views Asked by At

I try to make it work the sample for SCIM by Microsoft Microsoft.SCIM.WebHostSample.

I have publish on free Ad Azure for testing but I have an error with the getUsers API with call from test application (also in test Blazor application with authentication).

AuthenticationFailed: 'IDX10503: Signature validation failed. Keys tried: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: '-KI3Q9nNR7bRofxmeZoXqbHZGew', InternalId: 'b779cfa5-81bd-48ed-a4b1-52b5b4a4aaf4'. , KeyId: -KI3Q9nNR7bRofxmeZoXqbHZGew Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: '-KI3Q9nNR7bRofxmeZoXqbHZGew', InternalId: 'dc394ba5-6bae-43e7-ae70-64e24838c191'. , KeyId: -KI3Q9nNR7bRofxmeZoXqbHZGew Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'lHLIu4moKqzPcokwlfCRPHyjl5g', InternalId: '82045e96-8824-496a-ab13-e4964898d0f3'. , KeyId: lHLIu4moKqzPcokwlfCRPHyjl5g Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'lHLIu4moKqzPcokwlfCRPHyjl5g', InternalId: '09dc4323-e707-42e8-b8da-ed4ec7173157'. , KeyId: lHLIu4moKqzPcokwlfCRPHyjl5g '.

Exceptions caught:
System.NotSupportedException: IDX10634: Unable to create the SignatureProvider.
Algorithm: 'HS256', SecurityKey: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: '-KI3Q9nNR7bRofxmeZoXqbHZGew', InternalId: 'b779cfa5-81bd-48ed-a4b1-52b5b4a4aaf4'.
is not supported. The list of supported algorithms is available here: https://aka.ms/IdentityModel/supported-algorithms

at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, String algorithm, Boolean willCreateSignatures)
at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateForVerifying(SecurityKey key, String algorithm)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(Byte[] encodedBytes, Byte[] signature, ...

I send token get with GetToken API:

private async Task<string> GetToken()
{
    HttpClient cli = new HttpClient();

    HttpResponseMessage response = await cli.GetAsync("https://microsoftscimwebtest.azurewebsites.net/scim/Token");

    response.EnsureSuccessStatusCode();

    string token = await response.Content.ReadAsStringAsync();

    JObject obj = JObject.Parse(token);

    return obj.GetValue("token").ToString();
}

private async void Button_Click(object sender, RoutedEventArgs e)
{
    var token = await GetToken();

    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");

        // await client.GetAsync("https://microsoftscimwebtest.azurewebsites.net/scim/Users?attributes=userName");
        var result = await client.GetAsync("https://microsoftscimwebtest.azurewebsites.net/scim/Groups");

        if (!result.IsSuccessStatusCode)
        {
            throw new ArgumentException("error");
        }

        var jsonResult = await result.Content.ReadAsStringAsync();
    }
}

Thanks for help

0

There are 0 best solutions below