def delete(): oxc = oxdpython.Client(config_location) oxc.delete_config() values = oxc.get_config_value() if values["op_host"]: msg = 'delete failure' else: msg = 'Client deleted successfully' # delete object del oxc return render_template( "index.html", op_host=values["op_host"], client_name=values["client_name"], authorization_redirect_uri=values["authorization_redirect_url"], post_logout_uri=values["post_logout_redirect_uri"], port=values["connection_type_value"], oxd_id=values["id"], msg=msg)
def userinfo(): oxc = oxdpython.Client(config_location) code = request.args.get('code') state = request.args.get('state') if oxc.config.get("client", "dynamic_registration") == 'true': response = oxc.get_client_token() protection_access_token = response.access_token else: protection_access_token = '' tokens = oxc.get_tokens_by_code( code=code, state=state, protection_access_token=str(protection_access_token)) if oxc.config.get("client", "dynamic_registration") == 'true': newtokens = oxc.get_access_token_by_refresh_token( refresh_token=tokens.refresh_token, protection_access_token=str(protection_access_token)) access_token = newtokens.access_token else: access_token = tokens.access_token user = oxc.get_user_info( access_token=access_token, protection_access_token=str(protection_access_token)) session['username'] = user.name[0] session['usermail'] = user.email[0] userName = session['username'] userEmail = session['usermail'] # delete object del oxc return render_template('userinfo.html', userName=userName, userEmail=userEmail)
def protect(): oxc = oxdpython.Client(config_location) response = oxc.get_client_token() protection_access_token = response.access_token resources = [ {"path": "/photo", "conditions": [ { "scopes":["sobhan_uma_scope"], "ticketScopes":["sobhan_uma_scope"], "httpMethods":["GET"] } ] } ] result = oxc.uma_rs_protect(resources=resources, protection_access_token=str(protection_access_token)) # delete object del oxc return render_template('uma_test.html', msg=result)
def check_access(): oxc = oxdpython.Client(config_location) response = oxc.get_client_token() protection_access_token = response.access_token rpt = request.form['rpt'] path = '/photo' http_method = 'GET' result = oxc.uma_rs_check_access(rpt=str(rpt), path=path, http_method=http_method, protection_access_token=str(protection_access_token)) ticket = result.ticket #This is just for work around purpose. Original fix needs to be worked on. for i in result._fields: if 'hyphen' in i: newkey = i.replace('hyphen', '-') wwwauthenticate_header = getattr(result, "wwwhyphenauthenticate_header") decodeResponse = str(result) decodeResponse = decodeResponse.replace('hyphen', '-') # delete object del oxc return render_template('uma_test.html', ticket=ticket, rpt=rpt, msg=decodeResponse)
import os import sys from flask import Flask, render_template, redirect, request this_dir = os.path.dirname(os.path.realpath(__file__)) config = os.path.join(this_dir, 'demosite.cfg') oxd_path = os.path.dirname(this_dir) if oxd_path not in sys.path: sys.path.insert(0, oxd_path) import oxdpython app = Flask(__name__) oxc = oxdpython.Client(config) @app.route('/') def home(): return render_template("home.html") @app.route('/authorize/') def authorize(): """The endpoint which is to be accessed but the user in order to start the authorization by the user""" auth_url = oxc.get_authorization_url() return redirect(auth_url)
def setupClient(): oxc = oxdpython.Client(config_location) if request.method == 'GET': values = oxc.get_config_value() if values: #oxd_id present msg = 'Client already registered' else: msg = 'Enter data to register' return render_template( "index.html", op_host=values["op_host"], client_name=values["client_name"], authorization_redirect_uri=values["authorization_redirect_url"], post_logout_uri=values["post_logout_redirect_uri"], conn_value=values["connection_type_value"], oxd_id=values["id"], clientId=values["client_id"], clientSecret=values["client_secret"], conn_type=values["connection_type"], msg=msg, dynamic_registration=values["dynamic_registration"]) op_host = request.form['ophost'] client_name = request.form['client_name'] authorization_redirect_uri = request.form['redirect_uri'] post_logout_uri = request.form['post_logout_uri'] conn_type = request.form['conn_type_radio'] conn_type_value = request.form['conn_type_name'] try: client_id = request.form['ClientId'] client_secret = request.form['ClientSecret'] except: client_id = '' client_secret = '' ophost_type = oxc.openid_type(op_host) if not ophost_type and client_id == '': oxc.config.set("client", "dynamic_registration", "false") return render_template( "index.html", op_host=op_host, client_name=client_name, authorization_redirect_uri=authorization_redirect_uri, post_logout_uri=post_logout_uri, conn_value=conn_type_value, oxd_id='', msg='Enter clientID and clientSecret', conn_type=conn_type) if ophost_type: oxc.config.set("client", "dynamic_registration", "true") dynamic_registration = oxc.config.get("client", "dynamic_registration") client_data = oxc.setup_client( op_host=str(op_host), authorization_redirect_uri=str(authorization_redirect_uri), conn_type=str(conn_type), conn_type_value=str(conn_type_value), client_name=str(client_name), post_logout_uri=str(post_logout_uri), client_id=str(client_id), client_secret=str(client_secret)) oxd_id = client_data.oxd_id msg = "Client Set up completed successfully" client_id = client_data.client_id client_secret = client_data.client_secret # delete object del oxc return render_template( "index.html", op_host=op_host, client_name=client_name, authorization_redirect_uri=authorization_redirect_uri, post_logout_uri=post_logout_uri, conn_value=conn_type_value, oxd_id=oxd_id, clientId=client_id, clientSecret=client_secret, msg=msg, conn_type=conn_type, dynamic_registration=dynamic_registration)
def update(): oxc = oxdpython.Client(config_location) if request.method == 'GET': values = oxc.get_config_value() return render_template( 'index.html', op_host=values["op_host"], client_name=values["client_name"], authorization_redirect_uri=values["authorization_redirect_url"], post_logout_uri=values["post_logout_redirect_uri"], conn_value=values["connection_type_value"], oxd_id=values["id"], msg='click on edit to change', dynamic_registration=values["dynamic_registration"]) conn_type = request.form['conn_type_radio'] conn_type_value = request.form['conn_type_name'] try: client_id = request.form['ClientId'] client_secret = request.form['ClientSecret'] except: client_id = oxc.config.get("client", "client_id") client_secret = oxc.config.get("client", "client_secret") dynamic_registration = oxc.config.get("client", "dynamic_registration") if dynamic_registration == 'true': redirect_uri = request.form['redirect_uri'] client_name = request.form['client_name'] post_logout_uri = request.form['post_logout_uri'] response = oxc.get_client_token() protection_access_token = response.access_token status = oxc.update_site_registration( client_name=str(client_name), authorization_redirect_uri=str(redirect_uri), post_logout_uri=str(post_logout_uri), connection_type_value=str(conn_type_value), connection_type=str(conn_type), protection_access_token=str(protection_access_token)) else: oxc.config.set("oxd", "connection_type", conn_type) oxc.config.set("oxd", "connection_type_value", conn_type_value) oxc.config.set("client", "client_id", client_id) oxc.config.set("client", "client_secret", client_secret) status = "ok" values = oxc.get_config_value() if status == "ok": msg = 'Client updated successfully' else: msg = 'update failure' # delete object del oxc return render_template( "index.html", op_host=values["op_host"], client_name=values["client_name"], authorization_redirect_uri=values["authorization_redirect_url"], post_logout_uri=values["post_logout_redirect_uri"], conn_value=values["connection_type_value"], oxd_id=values["id"], clientId=values["client_id"], clientSecret=values["client_secret"], conn_type=values["connection_type"], msg=msg, dynamic_registration=values["dynamic_registration"])
import os import sys import logging import requests this_dir = os.path.dirname(os.path.realpath(__file__)) config = os.path.join(this_dir, 'native.cfg') oxd_path = os.path.dirname(this_dir) if oxd_path not in sys.path: sys.path.insert(0, oxd_path) import oxdpython client = oxdpython.Client(config) logging.basicConfig(level=logging.DEBUG) def get_auth_url(): logging.debug('Fetching authorization url.') auth_url = client.get_authorization_url(['oath']) logging.debug('Calling the auth_url: %s', auth_url) return auth_url def register(): logging.debug('Registering native app') oxid = client.register_site() logging.debug('Registration successful. ID: %s', oxid)