Coder Social home page Coder Social logo

flask_oneid's Introduction

Flask-OneID

GitHub Workflow Status (branch) GitHub release (latest by date) GitHub top language GitHub

Only for Uzbekistan

OneID integration for Flask application

Links

How it Works

Install

pip install Flask-OneID

Add your credentials from OneID to config file

ONEID_LOGIN = "your login"
ONEID_PASSWORD = "your pasword"
ONEID_URL = "url from OneID" # defaul https://sso.egov.uz/sso/oauth/Authorization.do 

Create Flask App With OneID

from flask_oneid import OneID
from flask import *
def create_app():
    oneid = OneID()
    app = Flask(__name__)
    app.config.from_pyfile('config.py')
    oneid.init_app(app)
    
    @app.route("/", methods=['GET'])
    def index():
        return "Hello World"
    
    return app

app = create_app()

if __name__ == "__main__":
    app.run(debug=True)

Add route to catch data from OneId

@app.route("/params", methods=['GET'])
def params():
    print(request.args)
    return redirect(url_for('index'))

Use builtin function to convert request args to dict

@app.route("/params", methods=['GET'])
def params():
    data = oneid.Params_To_Dict(request.args)
    print(data)
    return redirect(url_for('index'))

Register your Callback Url for OneID module

with app.test_request_context():
    oneid.Set_Callback(url_for('params'))

Full Code

from flask_oneid import OneID
from flask import *
def create_app():
    oneid = OneID()
    app = Flask(__name__)
    app.config.from_pyfile('config.py')
    oneid.init_app(app)
    
    @app.route("/", methods=['GET'])
    def index():
        return "Hello World"
    @app.route("/params", methods=['GET'])
    def params():
        data = oneid.Params_To_Dict(request.args)
        return jsonify(data)
    
    with app.test_request_context():
        oneid.Set_Callback(url_for('params'))
    return app

app = create_app()

if __name__ == "__main__":
    app.run(debug=True)

OneID route

After run app go to route /oneid/login to login oneid and get data about user

Return data

Example of data in callback

{
    "_pport_expr_date": "",
    "_pport_issue_date": "",
    "birth_date": "",
    "birth_place": "",
    "ctzn": "",
    "email": "",
    "first_name": "",
    "full_name": "",
    "gd": "",
    "legal_info": null,
    "mid_name": "",
    "mob_phone_no": "",
    "natn": "",
    "per_adr": "",
    "pin": "",
    "pport_expr_date": "",
    "pport_issue_date": "",
    "pport_issue_place": "",
    "pport_no": "",
    "ret_cd": "",
    "sess_id": "",
    "sur_name": "",
    "tin": "",
    "user_id": "",
    "user_type": "",
    "valid": ""
}

U can use it to create user and login with Flask-Admin

License

This project is licensed under the MIT License (see the LICENSE file for details).

flask_oneid's People

Contributors

odilxon avatar

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.