Example #1
0
 def create_app(self):
     try:
         #app = super(OAuth2ProviderTestCase, self).create_app()
         #app = api.create_app()
         app = factory.create_app('adsws.modules.oauth2server',
                 SQLALCHEMY_DATABASE_URI='sqlite://',
                 TESTING = True,
                 LOGIN_DISABLED = False, # necessary to exercise flask_login+oauth2
                 WTF_CSRF_ENABLED = False,
                 DEBUG=False,
                 SQLALCHEMY_ECHO = False,
                 SITE_SECURE_URL='http://localhost',
                 EXTENSIONS=['adsws.ext.template',
                             'adsws.ext.sqlalchemy', 
                             'adsws.ext.mail',
                             'adsws.ext.menu', 
                             'adsws.ext.security'],
                 PACKAGES=['adsws.modules.oauth2server'])
         app.testing = True
         app.config.update(dict(
             OAUTH2_CACHE_TYPE='simple',
         ))
         client = create_client(app, 'oauth2test')
         client.http_request = MagicMock(
             side_effect=self.patch_request(app)
         )
         db.create_all(app=app)
         return app
     except Exception as e:
         print(e)
         raise
Example #2
0
 def create_app(self):
     try:
         #app = super(OAuth2ProviderTestCase, self).create_app()
         #app = api.create_app()
         app = factory.create_app(
             'adsws.modules.oauth2server',
             SQLALCHEMY_DATABASE_URI='sqlite://',
             TESTING=True,
             LOGIN_DISABLED=False,  # necessary to exercise flask_login+oauth2
             WTF_CSRF_ENABLED=False,
             DEBUG=False,
             SQLALCHEMY_ECHO=False,
             SITE_SECURE_URL='http://localhost',
             EXTENSIONS=[
                 'adsws.ext.template', 'adsws.ext.sqlalchemy',
                 'adsws.ext.mail', 'adsws.ext.menu', 'adsws.ext.security'
             ],
             PACKAGES=['adsws.modules.oauth2server'])
         app.testing = True
         app.config.update(dict(OAUTH2_CACHE_TYPE='simple', ))
         client = create_client(app, 'oauth2test')
         client.http_request = MagicMock(
             side_effect=self.patch_request(app))
         db.create_all(app=app)
         return app
     except Exception as e:
         print(e)
         raise
Example #3
0
def get_app_config(key):
    from adsws.factory import create_app

    app = create_app('upgrade',
                     EXTENSIONS=['adsws.ext.sqlalchemy', 'adsws.ext.security'])
    with app.app_context() as c:
        print 'Getting actual config for', key
        return app.config.get(key)
Example #4
0
 def create_app(self):
     app = factory.create_app(
         SQLALCHEMY_BINDS=None,
         SQLALCHEMY_DATABASE_URI='sqlite://',
         EXTENSIONS=['adsws.ext.sqlalchemy'],
         DEBUG=False,
     )
     return app
Example #5
0
def get_app_config(key):
    from adsws.factory import create_app
    
    app = create_app('upgrade',
                     EXTENSIONS = ['adsws.ext.sqlalchemy',
                                   'adsws.ext.security'])
    with app.app_context() as c:
        print 'Getting actual config for', key
        return app.config.get(key)
def get_token():
  parser = argparse.ArgumentParser()
  add_arguments(parser)
  args = parser.parse_args()
  app = create_app('manual_client_registration',
    EXTENSIONS = ['adsws.ext.sqlalchemy',
                  'adsws.ext.security',],
    PACKAGES=['adsws.modules.oauth2server',])

  with app.app_context() as context:
    try:
      u = db.session.query(User).filter_by(email=args.user_email).one()
    except NoResultFound:
      if not args.create_user:
        sys.exit("User with email [%s] not found, and --create-user was not specified. Exiting." % args.user_email)
      u = User(email=args.user_email)
      db.session.add(u)
      db.session.commit()
    except MultipleResultsFound:
      raise DatabaseIntegrityError

    try:
      client = db.session.query(OAuthClient).filter_by(user_id=u.id,name=args.name).one()
    except MultipleResultsFound:
      raise DatabaseIntegrityError("Multiple oauthclients found for that user and name")
    except NoResultFound:
      client = OAuthClient(
        user_id = u.id,
        description=args.description,
        name=args.name,
        is_confidential=True,
        is_internal=True,)
      client.gen_salt()
      db.session.add(client)
      db.session.commit()

    try:
      tokens = db.session.query(OAuthToken).filter_by(
        client_id=client.client_id, 
        user_id=u.id, 
        is_personal=args.is_personal).all()
      #Iterate through each result and compare scopes
      matching_tokens = []
      for t in tokens:
        if set(args.scopes) == set(t.scopes):
          matching_tokens.append(t)
      if not matching_tokens:
        raise NoResultFound
      print "%s tokens with those definitions found, returning the first" % len(matching_tokens)
      token = matching_tokens[0]
    except NoResultFound:
      token = OAuthToken(
        client_id=client.client_id,
        user_id=u.id,
        access_token=gen_salt(current_app.config.get('OAUTH2_TOKEN_PERSONAL_SALT_LEN', 40)),
        refresh_token=gen_salt(current_app.config.get('OAUTH2_TOKEN_PERSONAL_SALT_LEN', 40)),
        _scopes=' '.join(args.scopes),
        expires=datetime.datetime(2050,1,1) if args.is_personal else None,
        is_personal=args.is_personal,
        is_internal=True,)
      db.session.add(token)
      db.session.commit()

    return {
      'access_token': token.access_token,
      'refresh_token': token.refresh_token,
      'username': u.email,
      'expires_in': token.expires.isoformat() if token.expires else None,
      'token_type': 'Bearer'}
Example #7
0
 def create_app(self):
     """Create the Flask application for testing."""
     app = create_app(**self.config)
     app.testing = True
     return app
Example #8
0
def get_token():
    parser = argparse.ArgumentParser()
    add_arguments(parser)
    args = parser.parse_args()
    app = create_app('manual_client_registration',
                     EXTENSIONS=[
                         'adsws.ext.sqlalchemy',
                         'adsws.ext.security',
                     ],
                     PACKAGES=[
                         'adsws.modules.oauth2server',
                     ])

    with app.app_context() as context:
        try:
            u = db.session.query(User).filter_by(email=args.user_email).one()
        except NoResultFound:
            if not args.create_user:
                sys.exit(
                    "User with email [%s] not found, and --create-user was not specified. Exiting."
                    % args.user_email)
            u = User(email=args.user_email)
            db.session.add(u)
            db.session.commit()
        except MultipleResultsFound:
            raise DatabaseIntegrityError

        try:
            client = db.session.query(OAuthClient).filter_by(
                user_id=u.id, name=args.name).one()
        except MultipleResultsFound:
            raise DatabaseIntegrityError(
                "Multiple oauthclients found for that user and name")
        except NoResultFound:
            client = OAuthClient(
                user_id=u.id,
                description=args.description,
                name=args.name,
                is_confidential=True,
                is_internal=True,
            )
            client.gen_salt()
            db.session.add(client)
            db.session.commit()

        try:
            tokens = db.session.query(OAuthToken).filter_by(
                client_id=client.client_id,
                user_id=u.id,
                is_personal=args.is_personal).all()
            #Iterate through each result and compare scopes
            matching_tokens = []
            for t in tokens:
                if set(args.scopes) == set(t.scopes):
                    matching_tokens.append(t)
            if not matching_tokens:
                raise NoResultFound
            print "%s tokens with those definitions found, returning the first" % len(
                matching_tokens)
            token = matching_tokens[0]
        except NoResultFound:
            token = OAuthToken(
                client_id=client.client_id,
                user_id=u.id,
                access_token=gen_salt(
                    current_app.config.get('OAUTH2_TOKEN_PERSONAL_SALT_LEN',
                                           40)),
                refresh_token=gen_salt(
                    current_app.config.get('OAUTH2_TOKEN_PERSONAL_SALT_LEN',
                                           40)),
                _scopes=' '.join(args.scopes),
                expires=datetime.datetime(2050, 1, 1)
                if args.is_personal else None,
                is_personal=args.is_personal,
                is_internal=True,
            )
            db.session.add(token)
            db.session.commit()

        return {
            'access_token': token.access_token,
            'refresh_token': token.refresh_token,
            'username': u.email,
            'expires_in': token.expires.isoformat() if token.expires else None,
            'token_type': 'Bearer'
        }
Example #9
0
 def create_app(self):
     """Create the Flask application for testing."""
     app = create_app(**self.config)
     app.testing = True
     return app
 def create_app(self):
     app = create_app(__name__)
     app.config["CLASSIC_LOGIN_URL"] = "http://foo.bar.org/cgi-bin/maint/manage_account/credentials"
     return app
Example #11
0
 def create_app(self):
     app = create_app(__name__)
     app.config[
         'CLASSIC_LOGIN_URL'] = 'http://foo.bar.org/cgi-bin/maint/manage_account/credentials'
     return app
Example #12
0
 def create_app(self):
     app = create_app(
         SQLALCHEMY_DATABASE_URI="sqlite://",
         EXTENSIONS=['adsws.ext.sqlalchemy'],
     )
     return app
Example #13
0
 def create_app(self):
     app = create_app(
         SQLALCHEMY_DATABASE_URI="sqlite://",
         EXTENSIONS=['adsws.ext.sqlalchemy'],
     )
     return app