Posted: 27/03/2024
Upgrading From IdentityServer Version 2 To IdentityServer Version 4
I have recently needed to upgrade from IdentityServer v2 to IdentityServer v4.
This was relatively painless (upgrade via nuget), but I had these 3 issues:
1 - PublicOrigin is no longer exposed, need to add it manually:
//Add in PublicOrigin as it has been removed in v4 of IdentityServer: https://github.com/IdentityServer/IdentityServer4/issues/4535 app.Use(async (ctx, next) => { ctx.SetIdentityServerOrigin("YourRequiredPublicOrigin"); await next(); });
2 - Add in ApiScopes :
.AddInMemoryApiScopes(ApiScopes.GetApiScopes())
Everything worked, except my Postman tests. Weird!
All my C# code was fine, which confused me.
After a lot of searching, I came across this page (English version) by Gabriel Bareclos.
It said:
I changed the content-type of the request from: form-data to: x-www-form-urlencoded .
So in my postman, I changed:
"mode": "formdata", "formdata": [
to this:
"mode": "urlencoded", "urlencoded": [
That was it. That fixed my postman tests!
Note - I should have looked at the docs again, although it is something that might pass you by:
POST /connect/token CONTENT-TYPE application/x-www-form-urlencoded client_id=client1& client_secret=secret& grant_type=authorization_code& code=hdh922& redirect_uri=https://myapp.com/callback
Thanks for reading this post.
If you want to reach out, catch me on Twitter!
I am always open to mentoring people, so get in touch.