IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

PersistedGrant record not created

Open ammar-haider opened this issue 10 years ago • 7 comments

Hi, I am trying IdSvr4 with and MVC Core and MVC5 to do SSO. When i login first from MVC5 app and then try MVC core app, it is fine and SSO works but not when I login using MVC Core first and then try MVC5. In the latter case a login form is again presented. The logs say "cookies was not authenticated. Unprotect ticket failed". Further i noticed that a record is created in PersistedGrants table for MVC5 app but never for MVC core app.

ammar-haider avatar Sep 14 '16 13:09 ammar-haider

For the consent: Are they configured as the same client, or different? Do they have different consent settings?

For the cookie: Where did you see this error? In IdentityServer, or in one of the clients?

brockallen avatar Sep 14 '16 13:09 brockallen

Hi Brock, i am not using consents for the time being. Cookie error is seen on the idsvr side. Thanks

ammar-haider avatar Sep 14 '16 14:09 ammar-haider

You will only see records in the grants table if you have authorization codes, refresh tokens, reference tokens, or user consent.

brockallen avatar Sep 14 '16 14:09 brockallen

all the records created so far have type as authorization_code. the following client conf was used to create database records for clients

`return new List {
//MVC5-A new Client { ClientId = "MVC5-A", ClientName = "MVC5 A", AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

                RequireConsent = false,

                RedirectUris = new List<string>
                {
                    "http://localhost:44306/signin-oidc"
                },

                PostLogoutRedirectUris = new List<string>
                {
                    "http://localhost:1278/"
                },

                ClientSecrets = new List<Secret>
                {
                    new Secret("secret".Sha256())
                },

                AllowedScopes = new List<string>
                {
                    StandardScopes.OpenId.Name,
                    StandardScopes.Profile.Name,
                    StandardScopes.Roles.Name,
                    StandardScopes.OfflineAccess.Name
                },

            },
            //MVC5-B client
            new Client
            {
                ClientId = "MVC5-B",
                ClientName = "MVC5 B",
                AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

                RequireConsent = false,

                RedirectUris = new List<string>
                {
                    "http://localhost:1278/signin-oidc"
                },

                PostLogoutRedirectUris = new List<string>
                {
                    "http://localhost:1278/"
                },

                ClientSecrets = new List<Secret>
                {
                    new Secret("secret".Sha256())
                },

                AllowedScopes = new List<string>
                {
                    StandardScopes.OpenId.Name,
                    StandardScopes.Profile.Name,
                    StandardScopes.Roles.Name,
                    StandardScopes.OfflineAccess.Name
                }
            },
            //MVC Core
            new Client
            {
                ClientId = "MVCCore",
                ClientName = "MVC Core",
                AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

                RequireConsent = false,

                RedirectUris = new List<string>
                {
                    "http://localhost:1278/signin-oidc"
                },

                PostLogoutRedirectUris = new List<string>
                {
                    "http://localhost:1278/"
                },

                ClientSecrets = new List<Secret>
                {
                    new Secret("secret".Sha256())
                },

                AllowedScopes = new List<string>
                {
                    StandardScopes.OpenId.Name,
                    StandardScopes.Profile.Name,
                    StandardScopes.Roles.Name,
                    StandardScopes.OfflineAccess.Name
                }
            }`

ammar-haider avatar Sep 14 '16 14:09 ammar-haider

Just to update, i could resolve the cookie issue and now MVC5 and MVC core both are working fine with single sign on. It was a data protection issue. However the PersistedGrant record isse remains. At one point a record was indeed created for MVC Core when i handled DataProctection issue at the MVC Core server side (not at the IdSvr4).

ammar-haider avatar Sep 15 '16 16:09 ammar-haider

If all you're doing is code flow, then the code persisted grant will only exist in the DB for a short while. Once the browser is redirected back to the MVC apps and they exchange the code for tokens, the code grant in the DB will be removed.

brockallen avatar Sep 15 '16 16:09 brockallen

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 15 '20 14:01 lock[bot]