Giter VIP home page Giter VIP logo

connexion_jwt_example's Introduction

Hello ๐Ÿ‡บ๐Ÿ‡ธ, Bonjour ๐Ÿ‡ซ๐Ÿ‡ท, Hallo ๐Ÿ‡ฉ๐Ÿ‡ช, ุงู„ุณู„ุงู… ุนู„ูŠูƒู… ๐Ÿ‡น๐Ÿ‡ณ ๐Ÿ‘‹

I'm Karim Jedda, I maintain a personal blog on karimjedda.com.

I'm the author of datawithrust.com and maintain arewedatayet.com.

My main socials are LinkedIn and Twitter. Feel free to reach out if you have any questions.

I'm currently working at Parity Technologies as a Senior Tech Lead, responsible for the Infrastructure & Data department.

connexion_jwt_example's People

Contributors

digitalist avatar karimjedda avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ansont digitalist

connexion_jwt_example's Issues

Parameters in yaml, crash functions with @jwt_required() decorator

Hi again @KarimJedda ,
I am just testing your stuff, and try to see some variations on your code.

I put parameters in yaml and in the zblaaaa.get_secret function

paths:
  '/stuff':
    get:
      tags: [stuff]
      operationId: zblaaaa.get_secret
      summary: Give me sugar sugar
      parameters:
        - name: animal_type
          in: query
          type: string
          pattern: "^[a-zA-Z0-9]*$"
        - name: limit
          in: query
          type: integer
          minimum: 0
          default: 100
      responses:
        200:
          description: Something secret

And here zblaaaa.get_secret, just remove your link to the video (sorry!) and added pets, of course! to test the parameters

from run import jwt_required, current_identity

pets = {
    "01": {
        "tags": ["dino","mamal"],
        "animal_type": "dino",
        "id": "01",
        "name": "Susie Saurio",
        "created": "2016-07-07T15:49:51.230+02:00"
    },
    "02":  {
        "tags": ["dino","bird"],
        "animal_type": "dino",
        "id": "02",
        "name": "Fly Saurio",
        "created": "2015-08-07T15:44:51.230+01:00"
    },
    "03":  {
        "tags": [],
        "animal_type": "bird",
        "id": "03",
        "name": "Piolin",
        "created": "2025-08-07T15:44:51.230+01:00"
    }
}

@jwt_required()
def get_secret(limit, animal_type=None):
    return [pet for pet in pets.values() if not animal_type or pet['animal_type'] == animal_type][:limit]

But after requiring the access_token, write back in header i retrieve the next error pointing to

*flask_jwt/init.py", line 177 in decorator
return fn(_args, _kwargs)
TypeError: get_secret() takes at least 1 argument (0 given)

ERROR:run:Exception on /api/stuff [GET]
Traceback (most recent call last):
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
 ....
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/validation.py", line 192, in wrapper
    response = function(*args, **kwargs)
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/produces.py", line 117, in wrapper
    data, status_code, headers = self.get_full_response(function(*args, **kwargs))
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/connexion/decorators/parameter.py", line 133, in wrapper
    return function(*args, **kwargs)
  File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/flask_jwt/__init__.py", line 177, in decorator
    return fn(*args, **kwargs)
TypeError: get_secret() takes at least 1 argument (0 given)
127.0.0.1 - - [2016-03-21 20:20:26] "GET /api/stuff?animal_type=dino&limit=100 HTTP/1.1" 500 377 0.003594

But i i remove the @jwt_required() from get_secret the response is 200.(OK)
So parameter definition is ok in yaml file.

Then, there is a problem in the @jwt_required() decorator. Isn't it?
Or Is in my test of this demo?

Thanks in advance

JWT in api.yaml file

Hi Karim!
Great Job!
Really good stuff!

I am trying to add your code to a list of end points and i want to set security in yaml file adding this

security:

  • $ref: '#/securityDefinitions/jwt'

before the paths section,
and remove the decorator @jwt_required() from the function that server the resources.

Is it possible? How? What is the syntax for that?

I just recived this error message validating the api.yaml

File "~/.pyenv/versions/miserver/lib/python2.7/site-packages/jsonschema/validators.py", line 123, in validate
raise error
swagger_spec_validator.common.SwaggerValidationError: 'apiKey' is not of type u'array'

Failed validating u'type' in schema[u'properties'][u'security'][u'items'][u'additionalProperties']:
{u'items': {u'type': u'string'},
u'type': u'array',
u'uniqueItems': True}

On instance[u'security'][0]['type']:
'apiKey'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.