def add_sso_token(request): try: sso_url = EveClient.get_instance().get_sso_url() return redirect(sso_url) except Exception: logger.exception("Failed to get SSO url from EveClient") messages.warning( request, "Eve Settings are not configured correctly. Contact your administrator." ) return redirect('/')
def sso_callback(request): code = request.GET.get('code', None) eve_client = EveClient.get_instance() # verify token esi_security = EveClient.get_esi_security() esi_token = esi_security.auth(code) esi_character = esi_security.verify() # create new token new_token = EveToken.objects.get_or_create( access_token=esi_token['access_token'], refresh_token=esi_token['refresh_token'], expires_in=esi_token['expires_in'], user=request.user)[0] # set scopes M2M scopes = EveScope.objects.filter(name__in=esi_character['scp']) if scopes.count() != len(esi_character['scp']): logger.error( f"Whoa there. Somehow we added a scope we don't know about. Pass this to Krypted Developers: \n ${esi_character['scp']}" ) new_token.scopes.set(scopes) # find or create character if EveCharacter.objects.filter( external_id=esi_character['sub'].split(":")[-1]).exists(): character = EveCharacter.objects.get( external_id=esi_character['sub'].split(":")[-1]) if character.token: old_token = character.token old_token.delete() character.token = new_token character.save() else: character = EveCharacter.objects.create( external_id=esi_character['sub'].split(":")[-1], name=esi_character['name'], token=new_token, ) # if no primary user, set if not PrimaryEveCharacterAssociation.objects.filter( user=request.user).exists(): PrimaryEveCharacterAssociation.objects.create(user=request.user, character=character) return redirect('/')
def sso_callback(request): code = request.GET.get('code', None) eve_client = EveClient.get_instance() # verify token esi_security = EveClient.get_esi_security() esi_token = esi_security.auth(code) esi_character = esi_security.verify() # create new token new_token = EveToken.objects.get_or_create( access_token=esi_token['access_token'], refresh_token=esi_token['refresh_token'], expires_in=esi_token['expires_in'], user=request.user)[0] # set scopes M2M new_token.scopes.set(EveScope.objects.all()) # find or create character if EveCharacter.objects.filter( external_id=esi_character['sub'].split(":")[-1]).exists(): character = EveCharacter.objects.get( external_id=esi_character['sub'].split(":")[-1]) if character.token: old_token = character.token old_token.delete() character.token = new_token character.save() else: character = EveCharacter.objects.create( external_id=esi_character['sub'].split(":")[-1], name=esi_character['name'], token=new_token, ) # if no primary token, set as primary token if not EveToken.objects.filter(user=request.user, primary=True).exists(): logger.info("Setting primary token as %s for %s" % (esi_character['name'], request.user)) new_token.primary = True new_token.save() update_character_corporation.apply_async(args=[character.external_id]) return redirect('app-dashboard') # TODO: Redirect to EVE Character view
def update_sso_token(request, token_id): eve_token = EveToken.objects.get(pk=token_id) return redirect(EveClient.get_instance().get_sso_url( EveScope.convert_to_list(eve_token.requested_scopes.all())))
def add_sso_token(request): return redirect(EveClient.get_instance().esi_sso_url)
def call(): EveClient.get_instance().save()