Repository: microsoft/onefuzz
File: src/cli/onefuzz/backend.py (Python)

Code before:

        if access_token:
            return access_token
        else:
            raise Exception("Failed to acquire token")

    def config_params(
        self,
    ) -> None:
        if self.config.endpoint is None:
            raise Exception("Endpoint Not Configured")

        endpoint = self.config.endpoint

        response = self.session.request("GET", endpoint + "/api/config")

        endpoint_params = responses.Config.parse_obj(response.json())

        # Will override values in storage w/ provided values for SP use
        if not self.config.client_id:
            self.config.client_id = endpoint_params.client_id
        if not self.config.authority:
            self.config.authority = endpoint_params.authority
        if not self.config.tenant_domain:
            self.config.tenant_domain = endpoint_params.tenant_domain

    def request(
        self,
        method: str,
        path: str,
        json_data: Optional[Any] = None,
        params: Optional[Any] = None,
        _retry_on_auth_failure: bool = True,
    ) -> Response:
        endpoint = self.config.endpoint

        if not endpoint:
            raise Exception("endpoint not configured")

        url = endpoint + "/api/" + path
        if not self.config.client_id or (
            not self.config.authority and not self.config.tenant_domain
        ):
            self.config_params()
        headers = self.headers()
        json_data = serialize(json_data)

        # 401 errors with IDX10501: Signature validation failed occur
        # on rolling new oauth2 client secrets

        # 404 errors happen when new revisions of the functions code are rolling out

Review comment (suggestion):
>Will override values in storage w/ provided values for SP use [](http://example.com/codeflow?start=10&length=61)

Is this comment correct?

Don't we want to just assign the values? What's the value of the test? #Closed

Code after:
                else:
                    continue

            LOGGER.info("Interactive device authentication succeeded")
            print("Login succeeded", flush=True)
            self.save_cache()
            break

        if access_token:
            return access_token
        else:
            raise Exception("Failed to acquire token")

    def config_params(
        self,
    ) -> None:
        if self.config.endpoint is None:
            raise Exception("Endpoint Not Configured")

        endpoint = self.config.endpoint

        response = self.session.request("GET", endpoint + "/api/config")

        endpoint_params = responses.Config.parse_obj(response.json())

        # Will override values in storage w/ provided values for SP use
        if not self.config.client_id:
            self.config.client_id = endpoint_params.client_id
        if not self.config.authority:
            self.config.authority = endpoint_params.authority
        if not self.config.tenant_domain:
            self.config.tenant_domain = endpoint_params.tenant_domain

    def request(
        self,
        method: str,
        path: str,
        json_data: Optional[Any] = None,
        params: Optional[Any] = None,
        _retry_on_auth_failure: bool = True,
    ) -> Response:
        endpoint = self.config.endpoint

        if not endpoint:
            raise Exception("endpoint not configured")

        url = endpoint + "/api/" + path
        if not self.config.client_id or (
            not self.config.authority and not self.config.tenant_domain
        ):
            self.config_params()