def setNameId(request, token): post = request.POST print(post) response = HttpResponse() if 'nameid' in post: version = '{}'.format(IMPERSONATION_VERSION) if version == "1": client = AppsClient('https://' + OKTA_ORG, API_KEY, IMPERSONATION_SAML_APP_ID) response.status_code = client.set_name_id( request.session['user_id'], post['nameid']) if version == "2": u_client = UsersClient('https://' + IMPERSONATION_V2_ORG, IMPERSONATION_V2_ORG_API_KEY) profile = request.session['profile'] users = u_client.list_user( json.loads(profile)['preferred_username']) users = json.loads(users) if "id" in users: client = AppsClient('https://' + IMPERSONATION_V2_ORG, IMPERSONATION_V2_ORG_API_KEY, IMPERSONATION_V2_SAML_APP_ID) response.status_code = client.set_name_id( users["id"], post['nameid']) for key in list(request.session.keys()): del request.session[key] return response
def setNameId(request, token): post = request.POST print(post) response = HttpResponse() if 'nameid' in post: name_id = post['nameid'] admin = request.session['profile']['preferred_username'] version = '{}'.format(IMPERSONATION_VERSION) if version == "1": client = AppsClient('https://' + OKTA_ORG, API_KEY, IMPERSONATION_SAML_APP_ID) response.status_code = client.set_name_id( request.session['id_token']['sub'], name_id) if version == "2": u_client = UsersClient('https://' + OKTA_ORG, API_KEY) target = json.loads(u_client.list_user(name_id)) target_profile = target["profile"] target_groups = json.loads(u_client.get_user_groups(target["id"])) groupsIds = [] for g in target_groups: if g["type"] != 'BUILT_IN': groupsIds.append(g["id"]) now = datetime.datetime.now() new_login = "******" + now.strftime('%Y%m%d%H%M%S') + admin.split( "@")[0].replace(".", "") + "AS" + target_profile["login"] target_profile["login"] = new_login target_profile["email"] = new_login temp_user = {"profile": target_profile, "groupIds": groupsIds} u_client.create_user(user=temp_user, activate=True) u_client = UsersClient('https://' + IMPERSONATION_V2_ORG, IMPERSONATION_V2_ORG_API_KEY) users = u_client.list_user(admin) users = json.loads(users) if "id" in users: client = AppsClient('https://' + IMPERSONATION_V2_ORG, IMPERSONATION_V2_ORG_API_KEY, IMPERSONATION_V2_SAML_APP_ID) response.status_code = client.set_name_id( users["id"], new_login) for key in list(request.session.keys()): del request.session[key] return response
def list_user(request, token): get = request.GET user_id = None if 'user' in get: user_id = get['user'] client = UsersClient('https://' + OKTA_ORG, API_KEY) if api_access_admin(token) or api_access_company_admin(token): users = client.list_user(user_id) else: return not_authorized(request) response = HttpResponse() response.status_code = 200 response.content = users return response
def list_user(request, access_token): conf = _get_config(request) get = request.GET user_id = None if 'user' in get: user_id = get['user'] client = UsersClient('https://' + conf['org'], config.get_api_key(request)) if api_access_admin(conf, access_token) or api_access_company_admin( conf, access_token): users = client.list_user(user_id) else: return not_authorized(request) response = HttpResponse() response.status_code = 200 response.content = users return response