1

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

sasy
  • 493
  • 3
  • 9
  • 21
  • Possible duplicate of [How to use swagger with OAuth API?](http://stackoverflow.com/questions/14884274/how-to-use-swagger-with-oauth-api) – Hack-R Dec 23 '16 at 07:17
  • 2
    You asked this a couple of hours ago, then deleted it and asked it again right? Please don't do that. You can edit your question all you like, but deleting and re-asking to try to get more attention is grounds for having your account banned. Note: users with >10,000 rep points can still see your deleted questions. – Hack-R Dec 23 '16 at 07:18
  • @Hack-R i have deleted it because I thought it's not clear, so that's why I posted new one – sasy Dec 23 '16 at 08:22
  • which is why @Hack-R mentioned the feature of editing your question. :) – David Ammouial Apr 20 '17 at 16:31

0 Answers0