Use Oauth in Swagger API

463 views Asked by At

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"

  security:
    - job_auth:
      - read:jobs `

In swagger editor , now it shows

Security job_auth (OAuth 2.0) Authenticate(Button)

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

0

There are 0 answers