mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-06 09:13:19 +03:00
🚀 Feature: Allow setting additional origins #299
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @andreas-soroko on GitHub.
Originally assigned to: @stonith404 on GitHub.
Feature description
a possibility to extend the
Access-Control-Allow-Originheader to allow other originsOIDC Clients -> Callback URLs(remove subpath if necessary) and allow them by default.Pitch
I have Pocket Id running via Docker and is accessible at
https://auth.dev.localhostwhich is fine and a frontend (React / SPA) running athttps://apps.dev.localhost.I also have an oidc client configured with the “public” flag enabled and wanted to add the client to the frontend for authentication. for this I am using oidc-react.
now the lib tries to reach the
.well-known/openid-configurationendpoint to load the metadata but this does not work because theAccess-Control-Allow-Originheader only allows thePUBLIC_APP_URLwhich points tohttps://auth.dev.localhost- the same for the other endpoints like the userinfo endpoint.so it is actually hardly possible to use the provider in the frontend in a decent way
@andreas-soroko commented on GitHub:
If it's a backend application, yop because they don't check the header.
You can simply test it your self - create any frontend application (should not on the same domain) and try to do the login via js code.
If I let my backend serve my frontend (instead of nginx) and secure
/via the backend (.NET) - yep then it works because it doesn't check the header.But that's not what my setup looks like.
my frontend runs in a nginx container on
apps.*, my backend onapi.*I had everything running with zitadel before and wanted to try something slightly more lightweight but without this setting option and token introspection (which looks like isn't support either), pocket-id is probably not for me
@kmendell commented on GitHub:
@stonith404 Can you provide insight here? Something isnt adding up to me , it could be cause its 1am, but still want you to read over as well.
@stonith404 commented on GitHub:
Yeah CORS aren't handled correctly at the moment. We have to find a good solution for this. It probably makes sense to add allowed origin for public clients.
@andreas-soroko commented on GitHub:
maybe some additional info:
i looked at what zitadel is doing at this point (because i thought i might be wrong?).
they always respond in the header (./wellknown/userinfo) with the domain that is doing the request.
and have tested it with 2 configured clients with different domains (
client1 = apps1.dev.localhost,client2 = apps2.dev.localhost)app1.*tries to login withclient1credentials, the header containsapps1.dev.localhostapp1.*tries to login withclient2credentials, the header containsapps1.dev.localhosttried then just for fun - visiting
google.comopening dev console and triedfetch('https://auth.dev.localhost/.well-known/openid-configuration')and it responded withhttps://www.google.comI am currently not sure what the correct implementation would look like or how other providers have solved this problem. I only know that it also worked with Keycloak as well - might try that again if I have some time.
the header=Access-Control-Allow-Origin@kmendell commented on GitHub:
After thinking more about this, it doesn't make sense, other clients can reach out to the well-knwon controller right? its only this one having the issue?
@paulgreg commented on GitHub:
I’ve got the same problem.
I’ve managed to make it work by adding the below configuration in nginx. However, it only works for a single client host so it would be great to be able to configure it client by client.
@savely-krasovsky commented on GitHub:
If I understood correctly, Pocket-ID for now doesn't support Single Page Applications which follow this draft RFC and basically obtain access/refresh tokens themselves. You need to manually set CORS headers?
@kmendell commented on GitHub:
i have a SPA that i use to test the OIDC spec and it works with pocket id just fine. i think this issue is different, it still open as we need to find a good solution to CORS
@kmendell commented on GitHub:
@stonith404 What is a ideal plan for this?
@magikid commented on GitHub:
I ran into this today using Traefik in front of all my services. I created a middleware that applies the correct CORS policies to my pocket ID ingress to resolve it.
I then added the annotation
traefik.ingress.kubernetes.io/router.middlewares: "default-pocket-id-cors@kubernetescrd"to my pocket ID ingress and it all started working.@Fred-06 commented on GitHub:
Hi,
This image (ghcr.io/pocket-id/pocket-id:development-cors) is always available ?
I have similar problem I think when I try to connect Owncloud Android app to my oCIS server.
Thank's !
@stonith404 commented on GitHub:
Would you mind to try the
ghcr.io/pocket-id/pocket-id:development-corsimage and let me know if the CORS errors are gone?Pocket ID should now allow all origins for endpoints that are needed for SPAs.
@chrismaster commented on GitHub:
use $http_origin
@savely-krasovsky commented on GitHub:
I had an experience to configure OpenCloud SPA and in fact it does require me to setup addition CORS header for Pocket ID.
@magikid commented on GitHub:
I deployed that image out and it seems to fix the CORS issue for me.
@savely-krasovsky commented on GitHub:
@Fred-06 this should be fixed. At least in my OpenCloud (oCIS fork) it's now works without any quirks.
@savely-krasovsky commented on GitHub:
@C8opmBM you need to create clients for every client:
Then you need to edit every Client ID and callback URLs to match OpenCloud documentation:
For example desktop requires those callback URLs:
Then I customized settings a bit to use
opencloud_roleclaim:And set
opencloud_roleclaim toopencloudAdminvalue.@savely-krasovsky commented on GitHub:
@C8opmBM web, desktop and iOS works for me. They didn't release Android app yet, so I cannot confirm it.
@C8opmBM commented on GitHub:
@savely-krasovsky wow, I didn't think that was possible yet. Would you share your desktop config/tutorial or make a comment here?
Thanks
@C8opmBM commented on GitHub:
@savely-krasovsky - do you have all your opencloud clients working? web, desktop, android/ios?
I edited the client IDs but still only the web client works.
@C8opmBM commented on GitHub:
Amazing!!! This little bit made the difference for me, the
:*after127...Now it works!
Thank you! I will update my guide in the opencloud discussion.
@savely-krasovsky commented on GitHub:
@C8opmBM usually
http://127.0.0.1is treated as special case for native applications, since they use random port. But Pocket-ID doesn't handle it unfortunately (I believe it should be fixed, since*could lead to potential vulnerabilities).@FrankelJb commented on GitHub:
Is it possible to set the IOS_CLIENT_ID as an environment variable? I can’t see a way to set the client id to OpenCloudIOS in pocket as the OC docs explain