Пример #1
0
 def get_user_info(self, password):
     self.log.info("Getting user info for username = "******"given_name": "first_name",
                 "middle_name": "middle_name",
                 "family_name": "last_name",
                 "email": "email",
                 "phone_number": "phone_number"
             })
     except Exception as e:
         print(str(e.with_traceback()))
     return user
Пример #2
0
async def verify_auth_header(authorization: HTTPBasicCredentials = Depends(auth)):
    """
    Verifies the credentials sent in the authorisation header with cognito
    """
    try:
        aws_cognito = Cognito(os.environ['USER_POOL_ID'],
                                os.environ['USER_POOL_WEB_CLIENT_ID'],
                                access_token=authorization.credentials)
        if aws_cognito.get_user() is None:
            raise HTTPException(status_code=403)

        return authorization.credentials
    except Exception as forbidden:
        raise HTTPException(status_code=403) from forbidden
Пример #3
0
def sign_in(user_sign_in: SignIn):
    aws_cognito = Cognito(os.environ['USER_POOL_ID'],
                          os.environ['USER_POOL_WEB_CLIENT_ID'])
    aws_cognito.username = user_sign_in.username
    aws_cognito.authenticate(password=user_sign_in.password)
    user = aws_cognito.get_user(attr_map={
        "usertype": "custom:usertype",
        "user_id": "sub"
    })
    usertype = user._data["custom:usertype"]
    user_id = user.sub
    resp = {
        "user": User(userId=user_id, username=user.username,
                     usertype=usertype),
        "token": Token(**aws_cognito.__dict__)
    }
    return SignInResponse(**resp)
Пример #4
0
def authenticate_user(username, password):
    try:
        u = Cognito(client_id=client_id,
                    user_pool_id=user_pool_id,
                    username=username,
                    user_pool_region='eu-west-1')
        u.authenticate(password=password)
        user = u.get_user(attr_map={"user_id": "sub"})
        user_id = user.sub

    except Exception as e:
        print("Incorrect username or password, please try again" + str(e))
        return False

    user_data = {
        'user_id': user_id,
        "username": username,
        "password": password
    }

    User.get_instance(user_data)  # instantiate singleton object
    return True