REST API? Add users via CLI + Acquire an access token #270
Replies: 2 comments
-
There are a few ways, how you can achieve all of this, but I need some more information. I guess you want to run tests against Rauthy in automated test pipelines and stuff, right?
Unfortunately, that's correct, they are not in the book yet. As I am getting closer to v1.0.0, one of my next TODO's is to update the docs with all the latest features that I added recently. API Keys are not yet in the book, but you should have no trouble getting them up and running by just using the Admin UI. Everything is documented and you even get Create a new API Key
So, either access it via the internal port, or just expose it with the config: If exposed, you can just click the link in the UI, if not, the URL would be something like
but on the
So, now to your goals. 1. SolutionCreate your whole instance like you need it, with everything set up. The version, again, depends on your environment. If you have some test postgres running somewhere, just connect to this instance inside the pipelines, so you data never changes. Otherwise, use the SQLite version of course. You could then provide your database file, which should be
You could do this dynamically with the API Key, or when you use the DB migration procedure from above, you can work with a static user as well, once it has been set up. Via API, you can do a POST on
That's actually the "tricky" part. You could of course just use the The code flow is done via a browser, like you mentioned already. To prevent Login CSRF attacks, you actually need a session in the backend in the rauthy/rauthy-main/tests/handler_auth.rs Line 72 in eec43bf You can extract the cookies like so: rauthy/rauthy-main/tests/common.rs Line 141 in eec43bf This is the only tricky part about it. Afterwards, you can do the POST, which will "redirect" you to your callback endpoint. You can then use the
That is simple. Just provide the
API yes, like mentioned above. Adding things by file is not supported. You would use the above approach with creating the test database just like you need it in advance and then just use that file inside your pipelines.
No. I planned to add something to inspect the token responses after you configured everything, so you can get a preview of what the final token for a given client + user would look like, but even when that comes, these tokens will not be valid and expire immediately for security reasons. 2. SolutionIf you are just using this for testing and nothing else, you could actually do the same that I do with Rauthy itself for its integration tests.
Also, the To start in test mode, you would however need to start the binary directly, or modify the docker run cmd and append 3. SolutionI need to double check something, but it might be possible with the |
Beta Was this translation helpful? Give feedback.
-
3. SolutionThis is actually working. I just checked it while testing the latest release.
The default scopes is the important one here. Since you cannot provide the requested scope during the This is way simpler than using the |
Beta Was this translation helpful? Give feedback.
-
Main goal is to identify a config file + CLI commands for supporting a test:
/userinfo
OIDC endpoint for a JSON response containing anemail
claim with that user email address.Presumably a mocked
/userinfo
endpoint that sends that JSON response when the auth header matches an expected hard-coded access token is simpler (current approach). I was just curious about automating integration with a proper auth server.I don't have much time presently to give Rauthy a try, just raising this Q in advance :)
Recently I was advised about using an API key to approach this:
I had a quick browse/search on the docs but I didn't see anything regarding an API key?
There's not much context about the API key, is there a REST API to use it with?
With Ory Hydra their API has routes under
admin/
that are advised to deployed with restricted access (eg via some auth header checks), I assume it's similar to that but Rauthy may be securing the endpoints via an API key by default?Use-case scenario
Technical reference
Initial interest was for replacing a mocked auth service for this test case (shell script based):
which is presently uses a hard-coded access token as shown above against this mocked
/userinfo
endpoint:The software makes a request to the auth service
/userinfo
endpoint with an access token:curl http://auth.example.test/userinfo -H 'Authorization: Bearer DMS_YWNjZXNzX3Rva2Vu'
and expects the JSON response to have an email attribute with a value that matches the login username to authenticate successfully:
I was curious if Rauthy can be configured with shell commands for the test-suite to replace that mocked service?:
The 2nd concern for acquiring an access token probably doesn't make much sense outside of a test? So the mocked endpoint with static access token is probably the right approach (and less burden to other project maintainers that don't really grok the actual auth process which is more complicated).
Earlier attempt
When I explored what was out there (such as Rauthy and Ory Hydra) this was all new to me and docs were not always straight-forward 😅
I recall having success with registering a client to Hydra where I could easily get the access token with credentials for that client, but that was only useful for a service to authenticate to another with, rather than the next step of getting the
/userinfo
endpoint to respond with user specific data.Rauthy from what I recall was focused on a DB + GUI interaction with an admin user, so I think I was more swayed towards Ory Kratos + Hydra due to their broader docs + CLI/API and config. I had also looked into Authelia and Authentik, but recall some friction on both of those (Authelia was a bit interesting as I think it could configure users via a file or LDAP source).
Ory Hydra did offer some alternative flows that did not require a browser interaction, but I ran out of time before having success with those via curl (I think I hit some issues there and their docs are a bit messy / outdated or oriented towards their paid SaaS).
Beta Was this translation helpful? Give feedback.
All reactions