Esempio n. 1
0
    def get_user_token(self, *, code: str, redirect_uri: Url) -> "UserToken":
        if not self.can_redirect_to(redirect_uri):
            raise ValueError(f"Can't redirect to {redirect_uri.raw}")
        data = {
            "grant_type": "authorization_code",
            "code": code,
            "redirect_uri": redirect_uri.raw,
            "client_id": self.clientId,
            "client_secret": self.secret,
        }
        print(f"postin this: \n{json.dumps(data)}")
        resp = requests.post(
            "https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/token",
            allow_redirects=False,
            data=data)
        print(f"Got this response: \n\n{resp.text}")
        resp.raise_for_status()

        data = ensureJsonObject(resp.json())
        return UserToken(
            access_token=ensureJsonString(data.get("access_token")),
            refresh_token=ensureJsonString(data.get("refresh_token")),
            # expires_in=data["expires_in"],
            # refresh_expires_in=data["refresh_expires_in"],
            # token_type=data["token_type"],
            # id_token=data["id_token"],
            # not_before_policy=data["not-before-policy"],
            # session_state=data["session_state"],
            # scope=data["scope"],
        )
Esempio n. 2
0
 def from_cookie(cls, request: web.Request) -> Optional["EbrainsSession"]:
     access_token = request.cookies.get(cls.AUTH_COOKIE_KEY)
     if access_token is None:
         return None
     user_token = UserToken(access_token=access_token)
     if not user_token.is_valid():
         return None
     return EbrainsSession(user_token=user_token)
Esempio n. 3
0
 async def from_cookie(
         cls, request: web.Request,
         http_client_session: ClientSession) -> Optional["EbrainsLogin"]:
     access_token = request.cookies.get(cls.AUTH_COOKIE_KEY)
     if access_token is None:
         return None
     user_token = UserToken(access_token=access_token)
     if not await user_token.is_valid(http_client_session):
         return None
     return EbrainsLogin(user_token=user_token)
Esempio n. 4
0
                        help="Number of minutes this workflow can run for")
    parser.add_argument("--ebrains-user-access-token", type=str, required=True)
    parser.add_argument("--listen-socket", type=Path, required=True)

    subparsers = parser.add_subparsers(required=False, help="tunnel stuff")
    tunnel_parser = subparsers.add_parser(
        "tunnel", help="Creates a reverse tunnel to an orchestrator")
    tunnel_parser.add_argument("--remote-username", type=str, required=True)
    tunnel_parser.add_argument("--remote-host", required=True)
    tunnel_parser.add_argument("--remote-unix-socket",
                               type=Path,
                               required=True)

    args = parser.parse_args()

    UserToken.login_globally(token=UserToken(
        access_token=args.ebrains_user_access_token))

    executor = get_executor(hint="server_tile_handler",
                            max_workers=multiprocessing.cpu_count())

    if "remote_username" in vars(args):
        server_context = ReverseSshTunnel(
            remote_username=args.remote_username,
            remote_host=args.remote_host,
            remote_unix_socket=args.remote_unix_socket,
            local_unix_socket=args.listen_socket,
        )
    else:
        server_context = contextlib.nullcontext()

    with server_context: