swagger-api / swagger-node

Swagger module for node.js
http://swagger.io
Apache License 2.0
3.97k stars 584 forks source link

How to use oauth In swagger API #469

Open Sasy91 opened 7 years ago

Sasy91 commented 7 years ago

Hi I'm building API using swagger and so far I created get/insert/update and delete jobs, and now I'm trying to use Oauth to secure my API

I have used

securityDefinitions: job_auth: type: oauth2 authorizationUrl: http://localhost:10010/auth flow: implicit scopes: write:jobs: modify jobs in your account read:jobs: get your jobs

And in my /get function i used `paths:

/jobs:

binds a127 app logic to a route

x-swagger-router-controller: job
get:
  description: Returns the job list
  # used as the method name of the controller
  operationId: getAllJobs
  responses:
    "200":
      description: Success
      schema:
        $ref: "#/definitions/GetJobsListResponse"
    # responses may fall through to errors
    default:
      description: Error
      schema:
        $ref: "#/definitions/ErrorResponse"
  security:
    - job_auth:
      - read:jobs `

In swagger editor , now it shows

Security job_auth (OAuth 2.0) Authenticate

Flow implicit Authorization URL http://localhost:10010/auth Scopes

write:jobs modify jobs in your account read:jobs get your jobs

now i want to access job list using http://localhost:10010/jobs

but it gives something like this

{ "message": "unknown security handler: job_auth", "code": "server_error", "statusCode": 403 }

can anyone help me how to access http://localhost:10010/jobs and set Authenticate in Oauth properly, I'm new to this

erosendale commented 5 years ago

I have the same issue almost 3 years later. Did you figure this out?