navikt / mock-oauth2-server

A scriptable/customizable web server for testing HTTP clients using OAuth2/OpenID Connect or applications with a dependency to a running OAuth2 server (i.e. APIs requiring signed JWTs from a known issuer)
MIT License
240 stars 57 forks source link

Support interactive login with pre-populated claims #696

Closed nealeu closed 3 months ago

nealeu commented 3 months ago

We often want to switch between different users with the same claims (or similar), but currently we have the choice of automatic login, or having to paste in the claims each time for interactive login (because password managers aren't helpful here).

Would you be happy to accept a PR to allow the following config to mean that the claims get populated within login.ftl?

{
    "interactiveLogin": true,
    "httpServer": "NettyWrapper",
    "tokenCallbacks": [
        {
            "issuerId": "issuer1",
            "tokenExpiry": 120,
            "requestMappings": [
                {
                    "requestParam": "scope",
                    "match": "scope1",
                    "claims": {
                        "sub": "subByScope",
                        "aud": ["audByScope"]
                    }
                }
            ]
        }
    ]
}

Such that the claims box would be automatically populated with { "sub": "subByScope", "aud": ["audByScope"] }.

This would greatly help our exploratory testing, as in the 90% case the user will just be hitting the login button, but the other 10% they may change the username or claims.

jp7677 commented 3 months ago

Look for loginPagePath in https://github.com/navikt/mock-oauth2-server?tab=readme-ov-file#json_config Within your own login page, all possibilities are open for e.g. adding buttons that prefill claims.

nealeu commented 3 months ago

Thanks. That did the trick.