def token_for(username): with app.app_context(): u = session.query(User).filter(User.username == username).first() if u: return _default_jwt_encode_handler(u) else: logging.error("There is no User with username={}".format(username))
def test_get_identity(self): """Check JWTHelper: get user identity""" with app.test_request_context(): mixer.init_app(app) user = mixer.blend(User) # Authenticate User self.auth = {'Authorization': "JWT " + _default_jwt_encode_handler(user)} with app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = {'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8')}
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = { 'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8') }
def test_get_identity(self): with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = {'Authorization': "JWT " + _default_jwt_encode_handler(user)} with app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = { 'Authorization': "JWT " + _default_jwt_encode_handler(user) }
def login(service: RegistrationService): form = AuthForm(data=request.get_json()) if not form.validate(): return {'success': False, 'errors': form.errors} success, errors = service.auth( email=form.email.data, password=form.password.data, ) if errors: form.email.errors.append(errors) return {'success': False, 'errors': form.errors} response = make_response({'success': True, 'errors': []}) response.set_cookie('auth_token', _default_jwt_encode_handler(current_user).decode()) return response
def test_get_identity(self): """Method to test identity of authenticated user""" with app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = { 'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8') } with app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def token(self): return _default_jwt_encode_handler(self).decode('utf-8')
def decorated(*args, **kwargs): if current_user and 'api_token' not in session: session['api_token'] = _default_jwt_encode_handler(current_user) return func(*args, **kwargs)
def decorated(*args, **kwargs): if current_user and 'api_token' not in session: session['api_token'] = _default_jwt_encode_handler(current_user) return func(*args, **kwargs)
def apikey(): key = _default_jwt_encode_handler(current_user) return render_template('api/apikey.html',apikey=key)
def create_token(profile): return _default_jwt_encode_handler(profile).decode()