Home > Backend Development > C#.Net Tutorial > Detailed explanation of IdentityServer4 SigningCredential (RSA certificate encryption) example

Detailed explanation of IdentityServer4 SigningCredential (RSA certificate encryption) example

零下一度
Release: 2018-05-22 16:08:07
Original
3156 people have browsed it

IdentityServer4 provides two certificate encryption configurations by default:

services.AddIdentityServer()
    .AddDeveloperSigningCredential()
    .AddTemporarySigningCredential();
Copy after login

These two certificate encryption methods are temporarily used every time the project is restarted. , will regenerate a new certificate, which will cause a problem. The access_token generated before restarting will no longer be applicable after the restart, because the certificate has changed and the corresponding encryption method has also changed. , so the following problem will occur:

Detailed explanation of IdentityServer4 SigningCredential (RSA certificate encryption) example

##Error message:

Www-Authenticate:Bearer error="invalid_token", error_description="The signature key was not found"

The solution is to always use one certificate. Let's configure it like this first:

services.AddIdentityServer()
    .AddDeveloperSigningCredential();
Copy after login

You can check it out

AddDeveloperSigningCredentialImplement the source code and start the project. IdentityServer4 will generate a tempkey.rsacertificate file in the project directory:

{
    "KeyId": "4e1765de45ef639261115198826dfea7",
    "Parameters": {
        "D": "FnB7kIinBgoZDaRqIrRQHEF45FBF9amOrTn8oFdmsxPqJbh11bHeCw11AtCCC4p1mm750onDXeP+yoBHymr/wNn40VmGdhR4hnObHhhw5pyQKECIS41DFDatCZif9uhDgHsOvYHMRVNSapDFoDUvbTE6t7rv4prn2fDt5mzRD9AqdT2HyTcwa/H1haaZNwmy3UevYYy8ya4kKXvjRo6+O7BMBh+yBvHgezQ57Ye/NfZfDMITs4djbqELrYVXCTMltNsWWhQtS62cqvKboxoiXfSm67u/li5Fdusc5Z2zsyt5rE/V8h/ffBvS9N9v0VoDTdFqLYkuul0DvTZ/pqXtMQ==",
        "DP": "XQDf46csbwu/xX+jwo5VQQ8sKVlVBLuxSNTAbNS6O/aCg9eEjZ58EJ712JgqqORcDMg5JRejN3Zxxoij4roJogyvvw6QSws/H+UTmtuuudgT59OB1TyNGihMVSTLXaw4Kgdj8D8IK8v0okdFEpYugzIIFe1yl0lSzR7fkF+NKC0=",
        "DQ": "4TvT9ujJ38sTluz0dUSIUD3NCWJOMDKOB/cL3RaDyMf/MTSxNFfWDuuW55F2P8mncHhqLuANcg2l3h8xom+1ucn+ve45JNoWja4fpWQ16rmijPc5yKRe0uAGEaXJiTAEvIxXG18zvNA8Fab+L2X1h+1r35ZLZFYj+EyhkqQ7u5k=",
        "Exponent": "AQAB",
        "InverseQ": "nTAEt8v+DlAn6h7Z1Ey1x4Z56OfOmCvY01nte4f3OuSmBXoEaTSoGsXScweAMoSGb0aOG1qpvErtY+JykREeLJxvm4P3DAHL5lJWvDKPvCWJOD9jfzhBUyIhCoqQ8EIHjFxBNKyNefAsVuKdH6R+ApuhpF8XVhR59zLawUQWLEg=",
        "Modulus": "43j4tvNZy7IxuiDwZzWv9KiS5kSYIeBqEvQ7zkQmRT3IEsseiTv698iQx8qn+de8FeGFEa8O6igFU2VXqFyWJilTuPmeBPJxIMCqfxdxF+96giVSpN4rOFaH/V+IPNTQoYCLFwcUR2saFywUeKWpsRFhQCymsFIk3AlWu7jcqgKHrELsJpn5KVmedb6JZcVKMIfTrcY6hWQz2JNEhTOEI10ZVZ7ueEp2Q2+1/udvp47wPMhzriXJTFP7Y4ozU2THbuwIqCXM5DNBGUpEug0vlCAhwn6nvAo8e9fT0lpUzTd2T8wWzwuHkAgyjB0XTzSYR1fMJIKH1zDs25RqmlepgQ==",
        "P": "9lGtQw9yXz4nbepESFDxAMfDlmiI9Gj3Q3FecKIgGVVi9WVr19lzBcszhsVybA8n1OyPXHdOyuSWOiVp69ibo5OOXLL4iWzY1VOouXeZrYimxNPvVKlRf8AsVcv3n/0/FEhwY9gnQm4PZYUGwQ96WZ5Z/CWJ9xTORg54Wh79hk0=",
        "Q": "7Gmr/h33bM+9W4Ygh+tNh3/etECuT/RQ1LMS5uBXxXdvUl6wSm2+ec/CBRobxVHG2pDXdr0pegn0Yz4MprsLtS5KvFg6yopI3Y3TptTGNZPtbd1O7P4i6b+RNOYCq0Y99mkGofqAlAMnDG+SA2EJN2ugPjLelC7GWtfzNG5NMgU="
    }
}
Copy after login

AddDeveloperSigningCredentialThe code in it will be executed first. Determine whether the tempkey.rsa certificate file exists. If it does not exist, create a new tempkey.rsa certificate file. If it exists, use this certificate file.

So, when we configure, just pass a

tempkey.rsa certificate file name:

services.AddIdentityServer()
    .AddDeveloperSigningCredential("tempkey.rsa");
Copy after login

Of course, you can also rename the

tempkey.rsa certificate file.

Reference:

  • The signature key was not found

  • IdentityServer4 Configuring services

  • IdentityServer4 Cryptography, Keys and HTTPS

  • ASP.NET Core implements the ResourceOwnerPassword and ClientCredentials modes of OAuth2.0

  • IdentityServerBuilderExtensionsCrypto.cs

The above is the detailed content of Detailed explanation of IdentityServer4 SigningCredential (RSA certificate encryption) example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template