예제 #1
0
파일: base.py 프로젝트: TeriForey/fawkes
    def authomatic_login(self):
        # LOGGER.debug('authomatic_login')
        _authomatic = authomatic(self.request)
        provider = self.request.matchdict.get('provider')

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response),
                                   provider)

        # LOGGER.debug('authomatic result: %s', result)
        # LOGGER.debug('authomatic response: %s', response)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                LOGGER.info("login successful for user %s", result.user.name)
                if result.provider.name == 'github':
                    # TODO: fix email ... get more infos ... which login_id?
                    login_id = "{0.username}@github.com".format(result.user)
                    return self.login_success(login_id=login_id,
                                              name=result.user.name)
                else:
                    # TODO: change login_id ... more infos ...
                    return self.login_success(login_id=result.user.id,
                                              email=result.user.email or '',
                                              openid=result.user.id,
                                              name=result.user.name
                                              or 'Unknown')
        return response
예제 #2
0
    def authomatic_login(self):
        _authomatic = authomatic(self.request)
        
        provider_name = self.request.matchdict.get('provider_name')

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response), provider_name)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                logger.info("login successful for user %s", result.user.name)
                if result.provider.name in ['openid', 'dkrz', 'ipsl', 'smhi', 'badc', 'pcmdi']:
                    # TODO: change login_id ... more infos ...
                    return self.login_success(login_id=result.user.id,
                                              email=result.user.email,
                                              openid=result.user.id,
                                              name=result.user.name)
                elif result.provider.name == 'github':
                    # TODO: fix email ... get more infos ... which login_id?
                    login_id = "{0.username}@github.com".format(result.user)
                    #email = "{0.username}@github.com".format(result.user)
                    # get extra info
                    if result.user.credentials:
                        pass
                    return self.login_success(login_id=login_id, name=result.user.name)
                elif result.provider.name == 'ceda':
                    return self.login_success(login_id='cedatest', name='cedatest')
        return response
예제 #3
0
    def authomatic_login(self):
        # LOGGER.debug('authomatic_login')
        _authomatic = authomatic(self.request)
        provider = self.request.matchdict.get('provider')

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response), provider)

        # LOGGER.debug('authomatic result: %s', result)
        # LOGGER.debug('authomatic response: %s', response)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                LOGGER.info("login successful for user %s", result.user.name)
                if result.provider.name == 'github':
                    # TODO: fix email ... get more infos ... which login_id?
                    login_id = "{0.username}@github.com".format(result.user)
                    return self.login_success(login_id=login_id, name=result.user.name)
                else:
                    # TODO: change login_id ... more infos ...
                    return self.login_success(login_id=result.user.id,
                                              email=result.user.email or '',
                                              openid=result.user.id,
                                              name=result.user.name or 'Unknown')
        return response
예제 #4
0
    def authomatic_login(self):
        # LOGGER.debug('authomatic_login')
        _authomatic = authomatic(self.request)
        provider = self.request.matchdict.get('provider')

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response), provider)

        LOGGER.debug('authomatic result: {}'.format(result))
        # LOGGER.debug('authomatic response: %s', response)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                LOGGER.debug("login successful for user {}".format(result.user.name))
                if result.provider.name == 'github':
                    return self.login_success(login_id=result.user.username, provider=result.provider.name,)
                elif result.provider.name == 'ceda_oauth':
                    return self.login_success(login_id=result.user.name, provider=result.provider.name,)
                elif result.provider.name == 'keycloak':
                    LOGGER.debug('credentials: {}'.format(result.provider.credentials))
                    client = KeycloakClient(self.request.registry)
                    user_info = client.introspect_access_token(result.provider.credentials.token)
                    return self.login_success(
                        login_id=user_info['preferred_username'],
                        provider=result.provider.name,
                        token={
                            'access_token': result.provider.credentials.token,
                            'refresh_token': result.provider.credentials.refresh_token,
                            'expires_in': result.provider.credentials.expire_in,
                            'expires_at': result.provider.credentials.expiration_time,
                            'token_type': result.provider.credentials.token_type,
                        })
                else:
                    raise Exception('Unknown provider')
        return response
예제 #5
0
    def authomatic_login(self):
        _authomatic = authomatic(self.request)

        provider_name = self.request.matchdict.get('provider_name')

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response),
                                   provider_name)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                logger.info("login successful for user %s", result.user.name)
                if result.provider.name in [
                        'openid', 'dkrz', 'ipsl', 'smhi', 'badc', 'pcmdi'
                ]:
                    # TODO: change login_id ... more infos ...
                    return self.login_success(login_id=result.user.id,
                                              email=result.user.email,
                                              openid=result.user.id,
                                              name=result.user.name)
                elif result.provider.name == 'github':
                    # TODO: fix email ... get more infos ... which login_id?
                    login_id = "{0.username}@github.com".format(result.user)
                    #email = "{0.username}@github.com".format(result.user)
                    # get extra info
                    if result.user.credentials:
                        pass
                    return self.login_success(login_id=login_id,
                                              name=result.user.name)
        return response
예제 #6
0
    def authomatic_login(self):
        from authomatic.adapters import WebObAdapter

        _authomatic = authomatic(self.request)

        provider_name = self.request.matchdict.get("provider_name")

        # Start the login procedure.
        response = Response()
        result = _authomatic.login(WebObAdapter(self.request, response), provider_name)

        if result:
            if result.error:
                # Login procedure finished with an error.
                return self.login_failure(message=result.error.message)
            elif result.user:
                if not (result.user.name and result.user.id):
                    result.user.update()
                # Hooray, we have the user!
                logger.info("login successful for user %s", result.user.name)
                if result.provider.name == "openid":
                    # TODO: change login_id ... more infos ...
                    return self.login_success(
                        login_id=result.user.id, email=result.user.email, openid=result.user.id, name=result.user.name
                    )
                elif result.provider.name == "github":
                    # TODO: fix email ... get more infos ... which login_id?
                    login_id = "{0.username}@github.com".format(result.user)
                    # email = "{0.username}@github.com".format(result.user)
                    # get extra info
                    if result.user.credentials:
                        pass
                    return self.login_success(login_id=login_id, name=result.user.name)
                elif result.provider.name == "ceda":
                    logger.warn("ceda login user=%s", result.user.data)
                    return self.login_success(login_id="cedatest", name="cedatest")
        return response