rookie-ninja / rk-boot

Build microservice with rk-boot and let the team take over clean and tidy code.
https://rk.mofcloud.com
Apache License 2.0
521 stars 60 forks source link

how can I find the jwt endpoints? #118

Closed MushiTheMoshi closed 2 years ago

MushiTheMoshi commented 2 years ago

Describe the bug A clear and concise description of what the bug is. Hi,

First of all, really nice work done here.

After setting up jwt middleware I am unable to acess sw even when ignore is set to /sw, how can I know jwt endpoints to get access token?

To Reproduce Steps to reproduce the behavior:

gin:
  - name: greeter                                          # Required
    port: 8080                                             # Required
    enabled: true                                          # Required
    commonService:
      enabled: true                                        # Optional, default: false
    sw:
      enabled: true                                        # Optional, default: false
    docs:
      enabled: true                                        # Optional, default: false
    middleware:
     jwt:
       enabled: true                                     # Optional, default: false
       ignorePrefix:                                      # Optional, default: []
         - "/sw"

Expected behavior after ignoring /sw I should be able to access sw and retrieve endpoints to get jwt token

Desktop (please complete the following information):

Smartphone (please complete the following information):

dongxuny commented 2 years ago

@MushiTheMoshi Hi, there are couple of steps we need to do if we hope to authorize API with JWT in swagger.

I created a demo at demo

Steps needs to follow for JWT in Swagger

Short demo

Please refer to code at demo

boot.yaml

---
gin:
  - name: greeter
    port: 8080
    enabled: true
    sw:
      enabled: true
    middleware:
      jwt:
        enabled: true
        ignore:
          - "/v1/login"
          - "/sw"

main.go

demo

Start server

go run main.go

Access swagger UI

http://localhost:8080/sw

Login

login

Authorize JWT in Swagger

Copy returned JWT token and authorize JWT authorise

Send /v1/whoami

success

MushiTheMoshi commented 2 years ago

Thank you so much the detailed explanation, I will test and let you know.

MushiTheMoshi commented 2 years ago

Hi there,

You are awesome! it worked like a charm!

Thank you so much for the example!

I am a newbie in terms of development, I really like the tool though I am not sure how to use in a structured application like a clean or hexagonal layout, do you think you can provide a quick example of it?

Thanks in advance for the help!

Regards, Julio