def serviceAuthorizations(request): authentication = platform_manager.authenticate(request) if 'error' in authentication: return HttpResponse(authentication['response']) user = authentication['user'] return_v = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str)))) applications = application_manager.getApplications() for application in applications: scopes = application_manager.getApplicationScopes(application) return_v[application._id]['name'] = application.name return_v[application._id]['owner'] = application.user.get_full_name() return_v[application._id]['description'] = application.description connectors = set() for scope in scopes: return_v[application._id]['scopes'][scope.scope]['description'] = scope.description connector = scope.connector connectors.add(connector) return_v[application._id]['scopes'][scope.scope]['status'] = getAuthorizationStatus(user, application, scope) return_v[application._id]['scopes'][scope.scope]['connector'] = connector.name for connector in connectors: uri = createUri(user, application, connector) return_v[application._id]['connectors'][connector.name]['grant_uri'] = uri['grant_uri'] return_v[application._id]['connectors'][connector.name]['revoke_uri'] = uri['revoke_uri'] return HttpResponse(json.dumps({'service': dict(return_v)}))
def serviceAuthorizations(request): authentication = platform_manager.authenticate(request) if 'error' in authentication: return HttpResponse(authentication['response']) user = authentication['user'] return_v = defaultdict( lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str)))) applications = application_manager.getApplications() for application in applications: scopes = application_manager.getApplicationScopes(application) return_v[application._id]['name'] = application.name return_v[application._id]['owner'] = application.user.get_full_name() return_v[application._id]['description'] = application.description connectors = set() for scope in scopes: return_v[application._id]['scopes'][ scope.scope]['description'] = scope.description connector = scope.connector connectors.add(connector) return_v[application._id]['scopes'][ scope.scope]['status'] = getAuthorizationStatus( user, application, scope) return_v[application._id]['scopes'][ scope.scope]['connector'] = connector.name for connector in connectors: uri = createUri(user, application, connector) return_v[application._id]['connectors'][ connector.name]['grant_uri'] = uri['grant_uri'] return_v[application._id]['connectors'][ connector.name]['revoke_uri'] = uri['revoke_uri'] return HttpResponse(json.dumps({'service': dict(return_v)}))
def userStatus(request): authentication = platform_manager.authenticate(request) if 'error' in authentication: return HttpResponse(authentication['response']) user = authentication['user'] response = {} response['applications'] = {} applications = application_manager.getApplications() if len(InformedConsent.objects.filter(user=user).all()) == 0: return HttpResponse(json.dumps({'error':'not enrolled'})) for application in applications: response['applications'][application.name] = {} response['applications'][application.name]['description'] = application.description response['applications'][application.name]['uri'] = application.url application_scopes = application_manager.getApplicationScopes(application) response['applications'][application.name]['scopes'] = {} for scope in application_scopes: if 'researcher' in scope.scope: continue auth = authorization_manager.authorization_manager.getAuthorization(user, scope, application) response['applications'][application.name]['scopes'][scope.scope] = {} response['applications'][application.name]['scopes'][scope.scope]['authorized'] = 1 if len(auth)>0 else 0 response['applications'][application.name]['scopes'][scope.scope]['description'] = scope.description response['applications'][application.name]['scopes'][scope.scope]['description_extra'] = scope.description_extra response['applications'][application.name]['scopes'][scope.scope]['auth_url'] = authorization_manager.authorization_manager.buildAuthUrl(scope.connector, application) return HttpResponse(json.dumps(response))
def userStatus(request): authentication = platform_manager.authenticate(request) if "error" in authentication: return HttpResponse(json.dumps(authentication)) user = authentication["user"] response = {"user_status": "unknown"} try: response["user_status"] = user.participant.status except Participant.DoesNotExist: return HttpResponse(json.dumps(response)) return HttpResponse(json.dumps(response))
def logout(request): response = {'error':'something went wrong'} try: auth = platform_manager.authenticate(request) if 'ok' in auth: token_user = auth['user'] sessions = Session.objects.filter(expire_date__gte=datetime.now()) for session in sessions: data = session.get_decoded() try: user = User.objects.filter(id=data.get('_auth_user_id', None))[0] except: continue if token_user == user: session.delete() response = {'ok':'user %s logged out'%user.username} except: pass return HttpResponse(json.dumps(response))
def logout(request): response = {'error': 'something went wrong'} try: auth = platform_manager.authenticate(request) if 'ok' in auth: token_user = auth['user'] sessions = Session.objects.filter(expire_date__gte=datetime.now()) for session in sessions: data = session.get_decoded() try: user = User.objects.filter( id=data.get('_auth_user_id', None))[0] except: continue if token_user == user: session.delete() response = {'ok': 'user %s logged out' % user.username} except: pass return HttpResponse(json.dumps(response))
def userStatus(request): authentication = platform_manager.authenticate(request) if 'error' in authentication: return HttpResponse(authentication['response']) user = authentication['user'] response = {} response['applications'] = {} applications = application_manager.getApplications() if len(InformedConsent.objects.filter(user=user).all()) == 0: return HttpResponse(json.dumps({'error': 'not enrolled'})) for application in applications: response['applications'][application.name] = {} response['applications'][ application.name]['description'] = application.description response['applications'][application.name]['uri'] = application.url application_scopes = application_manager.getApplicationScopes( application) response['applications'][application.name]['scopes'] = {} for scope in application_scopes: if 'researcher' in scope.scope: continue auth = authorization_manager.authorization_manager.getAuthorization( user, scope, application) response['applications'][application.name]['scopes'][ scope.scope] = {} response['applications'][application.name]['scopes'][ scope.scope]['authorized'] = 1 if len(auth) > 0 else 0 response['applications'][application.name]['scopes'][ scope.scope]['description'] = scope.description response['applications'][application.name]['scopes'][ scope.scope]['description_extra'] = scope.description_extra response['applications'][application.name]['scopes'][scope.scope][ 'auth_url'] = authorization_manager.authorization_manager.buildAuthUrl( scope.connector, application) return HttpResponse(json.dumps(response))