Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous access not working #917

Open
alexz707 opened this issue Jun 7, 2024 · 1 comment
Open

Anonymous access not working #917

alexz707 opened this issue Jun 7, 2024 · 1 comment

Comments

@alexz707
Copy link

alexz707 commented Jun 7, 2024

Hello,
I'm just digging into Mercure.
I've set up the docker image and also a Symfony Service to publish a topic update.
My docker config looks like that:

mercure:
        image: dunglas/mercure
        container_name: mercure
        environment:
            SERVER_NAME: ':80'
            MERCURE_PUBLISHER_JWT_KEY: 'THIS_IS_MY_SECRET_KEY'
            MERCURE_SUBSCRIBER_JWT_KEY: 'THIS_IS_MY_SECRET_KEY'
        command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
        ports:
            - "8080:80"

If added a JWT for the publisher with the key of the docker config and a * for the topics.

{
  "mercure": {
    "publish": [
      "tags"
    ],
    "subscribe": [
      "*"
    ],
    "payload": {
      "user": "alex",
      "remoteAddr": "localhost:8080"
    }
  }
}

It's working fine the topic update gets published.
If I go to the UI and want to subscribe to the topic everything works as long as I provide a valid JWT token for the subscriber.

{
  "mercure": {
    "subscribe": [
      "*"
    ],
    "payload": {
      "user": "alex",
      "remoteAddr": "localhost:8080"
    }
  }
}

Now if I want to use the anonymous subscription I tried to remove the JWT token (made sure it's not sent) and I also tried to use the Token but with a wrong JWT secret.
Both is not working - I always get back a 401 or in Firefox a NS_binding_abort with Unauthorized which is the same.

Maybe I understood something wrong but the anonymous mode should be enabled by the dev.Caddyfile.
And anonymous means I do not need to know the JWT secret - so how can I then subscribe to it?

the only way I got it working is to comment out the MERCURE_SUBSCRIBER_JWT_KEY in the docker config.

Is that the right way to do it? It's not clearly described in the docu.
Maybe someone can enlighten me ;-)
Thanks!

@sayou
Copy link

sayou commented Jun 9, 2024

As I understand from your topic, you can send special updates (a JWT Token is required to receive that update), and this is the point where I am facing an issue. Therefore, I would be grateful if you could give me more detailed and precise information (I am using Symfony 6 with API Platform).

As for your specific matter, in my Docker Compose file, I have this line, which might help you:

mercure:
        image: dunglas/mercure
        restart: unless-stopped
        ports:
            - 8082:8082
        networks:
            - dev
        environment:
            SERVER_NAME: ':8082'
            MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
            MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
            # Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive
            MERCURE_EXTRA_DIRECTIVES: |
                cors_origins http://localhost
                anonymous
        # Comment the following line to disable the development mode
        #command: /usr/bin/caddy run --config /etc/caddy/Caddyfile.dev --adapter caddyfile
        volumes:
            - mercure_data:/data
            - mercure_config:/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants