Skip to main content

OneID integration with Flask application, (only for Uzbekistan)

Project description

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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-OneID-1.0.2.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file Flask-OneID-1.0.2.tar.gz.

File metadata

  • Download URL: Flask-OneID-1.0.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for Flask-OneID-1.0.2.tar.gz
Algorithm Hash digest
SHA256 776fbb8357d2a456dd23b27e5d20a7485d57ea5eb73543321777360c920b0240
MD5 a571878943380a09285b04d5bdcba460
BLAKE2b-256 e5914a5c7aca49603ef7b05345e934c2f61ec2e4356fcbdb563c7e3b4fa4d6e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page