def setUp(self): """Create an authenticated session.""" # Specify the validity period for the session. start = datetime.now(tz=timezone('US/Eastern')) end = start + timedelta(seconds=36000) self.session = domain.Session( session_id='123-session-abc', start_time=start, end_time=end, user=domain.User( user_id='235678', email='*****@*****.**', username='******', name=domain.UserFullName('Jane', 'Bloggs', 'III'), profile=domain.UserProfile( affiliation='FSU', rank=3, country='de', default_category=domain.Category('astro-ph.GA'), submission_groups=['grp_physics'])), authorizations=domain.Authorizations( scopes=[ auth.scopes.CREATE_SUBMISSION, auth.scopes.EDIT_SUBMISSION, auth.scopes.VIEW_SUBMISSION ], endorsements=[ domain.Category('astro-ph.CO'), domain.Category('astro-ph.GA') ]))
def generate_client_token(client_id: str, owner_id: str, name: str, url: Optional[str] = None, description: Optional[str] = None, redirect_uri: Optional[str] = None, scope: str = DEFAULT_SCOPES, expires: int = 36000, endorsements: str = 'astro-ph.CO,astro-ph.GA', secret: str = DEFAULT_SECRET) -> None: # Specify the validity period for the session. start = datetime.now(tz=timezone('US/Eastern')) end = start + timedelta(seconds=expires) client = domain.Client(client_id=client_id, owner_id=owner_id, name=name, url=url, description=description, redirect_uri=redirect_uri) authorizations = domain.Authorizations( scopes=[domain.Scope(*s.split(':')) for s in scope.split()], endorsements=[ domain.Category(*cat.split('.', 1)) for cat in endorsements.split(',') ]) session = domain.Session(session_id=str(uuid.uuid4()), start_time=start, end_time=end, client=client, authorizations=authorizations) return auth.tokens.encode(session, secret)
def generate_token(user_id: str, email: str, username: str, first_name: str = 'Jane', last_name: str = 'Doe', suffix_name: str = 'IV', affiliation: str = 'Cornell University', rank: int = 3, country: str = 'us', default_category: str = 'astro-ph.GA', submission_groups: str = 'grp_physics', endorsements: Optional[str] = None, scope: str = DEFAULT_SCOPES) \ -> None: """Generate an auth token for dev/testing purposes.""" # Specify the validity period for the session. start = datetime.now(tz=timezone('US/Eastern')) end = start + timedelta(seconds=36000) # Make this as long as you want. if endorsements: these_endorsements = [ domain.Category(category) for category in endorsements.split(',') ] else: these_endorsements = [] session = domain.Session( session_id=str(uuid.uuid4()), start_time=start, end_time=end, user=domain.User( user_id=user_id, email=email, username=username, name=domain.UserFullName(first_name, last_name, suffix_name), profile=domain.UserProfile( affiliation=affiliation, rank=int(rank), country=country, default_category=domain.Category(default_category), submission_groups=submission_groups.split(','))), authorizations=domain.Authorizations( scopes=[domain.Scope(*s.split(':')) for s in scope.split()], endorsements=these_endorsements)) token = auth.tokens.encode(session, os.environ['JWT_SECRET']) click.echo(token)
def generate_token(user_id: str, email: str, username: str, first_name: str = 'Jane', last_name: str = 'Doe', suffix_name: str = 'IV', affiliation: str = 'Cornell University', rank: int = 3, country: str = 'us', default_category: str = 'astro-ph.GA', submission_groups: str = 'grp_physics', endorsements: str = 'astro-ph.CO,astro-ph.GA', scope: str = 'upload:read,upload:write,upload:admin') \ -> None: # Specify the validity period for the session. start = datetime.now(tz=UTC) end = start + timedelta(seconds=36000) # Make this as long as you want. # Create a user with endorsements in astro-ph.CO and .GA. session = domain.Session( session_id=str(uuid.uuid4()), start_time=start, end_time=end, user=domain.User( user_id=user_id, email=email, username=username, name=domain.UserFullName(first_name, last_name, suffix_name), profile=domain.UserProfile( affiliation=affiliation, rank=int(rank), country=country, default_category=domain.Category(default_category), submission_groups=submission_groups.split(',') ) ), authorizations=domain.Authorizations( scopes=[scope.split(',')], endorsements=[domain.Category(cat.split('.', 1)) for cat in endorsements.split(',')] ) ) token = auth.tokens.encode(session, app.config['JWT_SECRET']) click.echo(token)
def to_domain(self) -> domain.User: """Generate a :class:`.User` from this form's data.""" return domain.User( user_id=self.user_id.data if self.user_id.data else None, username=self.username.data, email=self.email.data, name=domain.UserFullName(forename=self.forename.data, surname=self.surname.data, suffix=self.suffix.data), profile=domain.UserProfile( affiliation=self.affiliation.data, country=self.country.data, rank=int(self.status.data), # WTF can't handle int values. submission_groups=self.groups.data, default_category=domain.Category( *self.default_category.data.split('.')), homepage_url=self.url.data, remember_me=self.remember_me.data))
def generate_token(user_id: str, email: str, username: str, first_name: str = 'Jane', last_name: str = 'Doe', suffix_name: str = 'IV', affiliation: str = 'Cornell University', rank: int = 3, country: str = 'us', default_category: domain.Category = (domain.Category( 'astro-ph', 'GA')), submission_groups: str = 'grp_physics', endorsements: List[domain.Category] = [], scope: List[domain.Scope] = []) -> None: """Generate an auth token for dev/testing purposes.""" # Specify the validity period for the session. start = datetime.now(tz=timezone('US/Eastern')) end = start + timedelta(seconds=36000) # Make this as long as you want. # Create a user with endorsements in astro-ph.CO and .GA. session = domain.Session( session_id=str(uuid.uuid4()), start_time=start, end_time=end, user=domain.User(user_id=user_id, email=email, username=username, name=domain.UserFullName(first_name, last_name, suffix_name), profile=domain.UserProfile( affiliation=affiliation, rank=int(rank), country=country, default_category=default_category, submission_groups=submission_groups.split(','))), authorizations=domain.Authorizations(scopes=scope, endorsements=endorsements)) token = auth.tokens.encode(session, os.environ['JWT_SECRET']) return token