Generate username based on claims.
349569
def get_username(self, claims):
        """"""
        # bluntly stolen from django-browserid
        # https://github.com/mozilla/django-browserid/blob/master/django_browserid/auth.py
        username_algo = self.get_settings('OIDC_USERNAME_ALGO', None)

        if username_algo:
            if isinstance(username_algo, six.string_types):
                username_algo = import_string(username_algo)
            return username_algo(claims.get('email'))

        return default_username_algo(claims.get('email'))
459376
def generate(self):
        """"""
        payload = {
            'algorithm': 'HMAC-SHA256'
        }

        if self.data:
            payload['app_data'] = self.data

        if self.page:
            payload['page'] = {}

            if self.page.id:
                payload['page']['id'] = self.page.id

            if self.page.is_liked:
                payload['page']['liked'] = self.page.is_liked

            if self.page.is_admin:
                payload['page']['admin'] = self.page.is_admin

        if self.user:
            payload['user'] = {}

            if self.user.country:
                payload['user']['country'] = self.user.country

            if self.user.locale:
                payload['user']['locale'] = self.user.locale

            if self.user.age:
                payload['user']['age'] = {
                    'min': self.user.age[0],
                    'max': self.user.age[-1]
                }

            if self.user.oauth_token:

                if self.user.oauth_token.token:
                    payload['oauth_token'] = self.user.oauth_token.token

                if self.user.oauth_token.expires_at is None:
                    payload['expires_in'] = 0
                else:
                    payload['expires_in'] = int(time.mktime(self.user.oauth_token.expires_at.timetuple()))

                if self.user.oauth_token.issued_at:
                    payload['issued_at'] = int(time.mktime(self.user.oauth_token.issued_at.timetuple()))

        if self.user.id:
            payload['user_id'] = self.user.id

        encoded_payload = base64.urlsafe_b64encode(
            json.dumps(payload, separators=(',', ':')).encode('utf-8')
        )

        encoded_signature = base64.urlsafe_b64encode(hmac.new(
            self.application_secret_key.encode('utf-8'),
            encoded_payload,
            hashlib.sha256
        ).digest())

        return '%(signature)s.%(payload)s' % {
            'signature': encoded_signature,
            'payload': encoded_payload
        }
1112864
def _get_user(self, user):
        """"""
        return ' '.join([user.username, user.first_name, user.last_name])
781724
def __username(self, fname, lname):  # pragma: no cover
        """"""
        self.username = '.'.join([i.lower() for i in [fname, lname]])
430803
def get_claimed_username(token):
    
    unverified_data = jwt.decode(token, options={
        'verify_signature': False
    })

    if 'username' not in unverified_data:
        return None
    return unverified_data['username']
254589
def get_user_claims(self, access_token, claims=None, token_type='Bearer'):
        """"""
        data = self.get_json(
            self.USER_INFO_URL,
            headers={'Authorization': '{token_type} {token}'.format(token_type=token_type, token=access_token)}
        )

        if claims:
            claims_names = set(claims)
            data = {k: v for (k, v) in six.iteritems(data) if k in claims_names}

        return data
1237143
@ShellMethod(key = "generate-anonymous-user", value = "Generate an anonymous (persistent) username identifier")
    public void generateUsername(
        @ShellOption(value = {"username"},
            help = "Authenticated username") final String username,
        @ShellOption(value = {"service"},
            help = "Service application URL for which CAS may generate the identifier") final String service,
        @ShellOption(value = {"salt"},
            help = "Salt used to generate and encode the anonymous identifier") final String salt) {
        val generator = new ShibbolethCompatiblePersistentIdGenerator(salt);
        val id = generator.generate(username, service);
        LOGGER.info("Generated identifier:\n[{}]", id);
    }
579537
def token_gen_call(username, password):
    """"""
    secret_key = 'super-secret-key-please-change'
    mockusername = 'User2'
    mockpassword = 'Mypassword'
    if mockpassword == password and mockusername == username: # This is an example. Don't do that.
        return {"token" : jwt.encode({'user': username, 'data': 'mydata'}, secret_key, algorithm='HS256')}
    return 'Invalid username and/or password for user: {0}'.format(username)
1352078
def _get_credentials_from_settings(self):
        """"""
        remember_me = CONF.get('main', 'report_error/remember_me')
        remember_token = CONF.get('main', 'report_error/remember_token')
        username = CONF.get('main', 'report_error/username', '')
        if not remember_me:
            username = ''

        return username, remember_me, remember_token
735214
def id_generator(size=15, random_state=None):
    """"""
    chars = list(string.ascii_uppercase + string.digits)
    return ''.join(random_state.choice(chars, size, replace=True))
1029190
def generate_id():
    """"""
    # TODO: Use six.string_type to Py3 compat
    try:
        return unicode(uuid1()).replace(u"-", u"")
    except NameError:
        return str(uuid1()).replace(u"-", u"")
927359
def _CaptureUserId(self):
    """"""
    user_kind, user_id = user_id_collector()
    if user_kind and user_id:
      self.breakpoint['evaluatedUserId'] = {'kind': user_kind, 'id': user_id}
825252
def generate_admin_metadata(name, creator_username=None):
    """"""

    if not dtoolcore.utils.name_is_valid(name):
        raise(DtoolCoreInvalidNameError())

    if creator_username is None:
        creator_username = dtoolcore.utils.getuser()

    datetime_obj = datetime.datetime.utcnow()

    admin_metadata = {
        "uuid": str(uuid.uuid4()),
        "dtoolcore_version": __version__,
        "name": name,
        "type": "protodataset",
        "creator_username": creator_username,
        "created_at": dtoolcore.utils.timestamp(datetime_obj)
    }
    return admin_metadata
386227
def _quote_username(name):
    '''
    
    '''
    if not isinstance(name, six.string_types):
        return str(name)  # future lint: disable=blacklisted-function
    else:
        return salt.utils.stringutils.to_str(name)
1070232
def get_username(self, userid):
        '''
        '''

        username = self.user_map.get(userid)
        if not username:
            users = self.get_users()
            if users:
                members = {
                    m['id']: m['name']
                    for m in users.get('members', [{}])
                    if m.get('id')
                    and m.get('name')
                }
                if members:
                    self.user_map.update(members)

                username = self.user_map.get(userid, userid)

        return username
1348057
def _get_user(self, username):
        """"""
        data = self.client.get(self._key(username))
        if data is None:
            return None
        return json.loads(data.decode())
920200
def generate_username(self, user_class):
        
        m = getattr(user_class, 'generate_username', None)
        if m:
            return m()
        else:
            max_length = user_class._meta.get_field(
                self.username_field).max_length
            return uuid.uuid4().hex[:max_length]