Coder Social home page Coder Social logo

Comments (3)

ergoz avatar ergoz commented on June 6, 2024

I found how can i do this!!! I spent 1 week to find, and only after i creat this issue ticket i spent 5 minutes and it works!

i made auth.py

from functools import wraps
from flask import request, Response, g
from app import jsonrpc
from flask_jsonrpc.exceptions import InvalidCredentialsError

def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    return username == 'admin' and password == 'admin'

def requires_rpc_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            raise InvalidCredentialsError()
        g.auth = auth
        return f(*args, **kwargs)
    return decorated

and in main file:

from app import jsonrpc
from app.lib import auth
from flask import g


@jsonrpc.method('Index.hello')
@auth.requires_rpc_auth
def hello(name):
    return u'Hello {0} {1}'.format(name, g.auth.username)

LOL :)

Sorry for bad english :)

from flask-jsonrpc.

nycholas avatar nycholas commented on June 6, 2024

😄 no problem, thank you!

from flask-jsonrpc.

ergoz avatar ergoz commented on June 6, 2024

I hope this info will help to noobies like me :)

from flask-jsonrpc.

Related Issues (20)

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.