def _dolly_token(userid): try: from rockpack.mainsite.core.token import create_access_token except ImportError: return 'xxx' else: return create_access_token(userid, '', 0)
def reset_dolly_tokens(): try: from rockpack.mainsite.core.token import create_access_token except ImportError: create_access_token = lambda u, c, a: 'xxx' for account in Account.query.all(): account.dolly_token = create_access_token(account.dolly_user, '', 0) db.session.commit()
def test_access_token_authentication(self): with self.app.test_client() as client: client_id = uuid.uuid4().hex user = self.create_test_user() token = create_access_token(user.id, client_id, 3600) r = self._call_url( client, "/test/oauth2/access_token_header/?user_id={}".format(user.id), headers={"Authorization": "Bearer {}".format(token)}, ) self.assertEquals(200, r.status_code)
def send_password_reset(userid): user = User.query.get(userid) if not user.email: app.logger.warning("Can't reset password for %s: no email address", user.id) return token = create_access_token(user.id, '', 86400) url = url_for('reset_password') + '?token=' + token template = email_env.get_template('reset.html') body = template.render( reset_link=url, user=user, email_sender=app.config['DEFAULT_EMAIL_SOURCE'], ) send_email(user.email, body)
def get_credentials(self, expires_in=None): if expires_in is None: expires_in = app.config.get('ACCESS_TOKEN_EXPIRY', 3600) # This is mostly used in oauth/api.py where `app_client_id` is set in the # `check_client_authorization` decorator from the Basic auth token. `client_id` # is set in `check_authorization` from the Bearer token. try: client_id = g.app_client_id except AttributeError: client_id = g.authorized.clientid access_token = create_access_token(self.id, client_id, expires_in) return dict( token_type='Bearer', access_token=access_token, expires_in=expires_in, refresh_token=self.refresh_token, user_id=self.id, resource_url=self.get_resource_url(own=True), )
def get_auth_header(userid): from rockpack.mainsite.core.token import create_access_token return 'Authorization', 'Bearer %s' % create_access_token(userid, '', 60)