Retrieve the request's User-Agent, if available.

        Taken from Flask Login utils.py.
439075
def _get_user_agent(self):
        
        user_agent = request.headers.get('User-Agent')
        if user_agent:
            user_agent = user_agent.encode('utf-8')
        return user_agent or ''
138542
def get_session(user_agent):
    """"""

    client = requests.Session()
    client.headers.update({
        'Content-Type': 'application/json',
        'User-Agent': user_agent,
    })
    retry = Retry(connect=3, backoff_factor=3)
    adapter = HTTPAdapter(max_retries=retry)
    client.mount('https://', adapter)
    return client
79949
def current(self):
        
        if not has_request_context():
            return self.no_req_ctx_user_stack.top
        user_stack = getattr(_request_ctx_stack.top, 'user_stack', None)
        if user_stack and user_stack.top:
            return user_stack.top
        return _get_user()
872707
def user(self):
        
        if self._user is not None:
            return self._user

        cert = self.transport.getPeerCertificate()
        self._user = user = userForCert(self.store, cert)
        return user
1244100
def get_current_user(self):
        
        from google.appengine.api import users

        if _IS_DEVELOPMENT_SERVER:
            return users.get_current_user()
        else:
            from google.appengine.api import oauth

            try:
                user = oauth.get_current_user()
            except oauth.OAuthRequestError:
                user = users.get_current_user()
            return user
492283
def requester(self):
        
        if self.api and self.requester_id:
            return self.api._get_user(self.requester_id)
442801
private Object checkUserAgent(RequestResponseClass clazz, ApiUser userAgent) {
        if(clazz.getUserClass().isAssignableFrom(userAgent.getClass()))
            return userAgent;
        return UserAgentUtil.getGameUser(userAgent, clazz.getUserClass());
    }
634209
def get(self, request):
        
        code = request.GET.get("code")

        if not code:
            # Return an error message
            return render(request, 'django_auth_adfs/login_failed.html', {
                'error_message': "No authorization code was provided.",
            }, status=400)

        redirect_to = request.GET.get("state")

        user = authenticate(request=request, authorization_code=code)

        if user is not None:
            if user.is_active:
                login(request, user)
                # Redirect to the "after login" page.
                # Because we got redirected from ADFS, we can't know where the
                # user came from.
                if redirect_to:
                    redirect_to = base64.urlsafe_b64decode(redirect_to.encode()).decode()
                else:
                    redirect_to = django_settings.LOGIN_REDIRECT_URL
                url_is_safe = is_safe_url(
                    url=redirect_to,
                    allowed_hosts=[request.get_host()],
                    require_https=request.is_secure(),
                )
                redirect_to = redirect_to if url_is_safe else '/'
                return redirect(redirect_to)
            else:
                # Return a 'disabled account' error message
                return render(request, 'django_auth_adfs/login_failed.html', {
                    'error_message': "Your account is disabled.",
                }, status=403)
        else:
            # Return an 'invalid login' error message
            return render(request, 'django_auth_adfs/login_failed.html', {
                'error_message': "Login failed.",
            }, status=401)
551465
def get_user(self, userPk):
        """"""
        r = self._request('user/' + str(userPk))
        if r:
            # Set base properties and copy data inside the user
            u = User()
            u.pk = u.id = userPk
            u.__dict__.update(r.json())
            return u
        return None
835413
def __get_user(self):
        
        storage = object.__getattribute__(self, '_LazyUser__storage')
        user = getattr(self.__auth, 'get_user')()
        setattr(storage, self.__user_name, user)
        return user
100603
def my_request_classifier(environ):
    
    request_method = REQUEST_METHOD(environ)
    if request_method in _DAV_METHODS:
        return "dav"
    useragent = USER_AGENT(environ)
    if useragent:
        for agent in _DAV_USERAGENTS:
            if useragent.find(agent) != -1:
                return "dav"
    if request_method == "POST":
        if CONTENT_TYPE(environ) == "text/xml":
            return "xmlpost"
        elif CONTENT_TYPE(environ) == "application/soap+xml":
            return "soap"
    return "browser"
1150093
def get_auth_user():
    
    from uliweb import request
    from uliweb import settings

    user_fieldname = settings.get_var('AUTH/GET_AUTH_USER_FIELDNAME', 'id')

    session_key = _get_auth_key()
    user_id = request.session.get(session_key)
    if user_id:
        if isinstance(user_id, dict):
            return user_id
        else:
            User = get_model('user')
            user = User.get(User.c[user_fieldname]==user_id)
            return user
1309092
def get_user(self, name):
        
        return self._api_get('/api/users/{0}'.format(
            urllib.parse.quote_plus(name)
        ))
1257769
def get_user(request):
    
    user = None
    try:
        user_id = request.session[SESSION_KEY]
        token = request.session[AUTH_TOKEN_SESSION_KEY]
        user_data = request.session[USER_DATA_SESSION_KEY]
        backend_path = request.session[BACKEND_SESSION_KEY]
    except KeyError:
        pass
    else:
        if backend_path in settings.AUTHENTICATION_BACKENDS:
            backend = load_backend(backend_path)
            user = backend.get_user(user_id, token, user_data)
            # Verify the session
            if hasattr(user, 'get_session_auth_hash'):
                session_hash = request.session.get(HASH_SESSION_KEY)
                session_hash_verified = session_hash and constant_time_compare(
                    session_hash,
                    user.get_session_auth_hash()
                )
                if not session_hash_verified:
                    request.session.flush()
                    user = None

    return user or MojAnonymousUser()
742395
def get_user_token(self):
        
        headers = { 'User-Agent': self.user_agent(),
                'Host': self.domain(),
                'Accept': '*/*',
        }
        headers.update(self.headers())
        r = requests.get(   self.portals_url()+'/users/_this/token',
                            headers=headers,
                            auth=self.auth())
        if HTTP_STATUS.OK == r.status_code:
            return r.text
        else:
            print("get_user_token: Something went wrong: <{0}>: {1}".format(
                        r.status_code, r.reason))
            r.raise_for_status()
1365834
def get_user(
        self, identified_with, identifier, req, resp, resource, uri_kwargs
    ):
        """"""
        return self.user
126510
def _extract_info_from_useragent(user_agent):
    """"""
    parsed_string = user_agent_parser.Parse(user_agent)
    return {
        'os': parsed_string.get('os', {}).get('family'),
        'browser': parsed_string.get('user_agent', {}).get('family'),
        'browser_version': parsed_string.get('user_agent', {}).get('major'),
        'device': parsed_string.get('device', {}).get('family'),
    }