我如何修复“无法解析JWT”身份意识到代理的错误?

发布于 2025-01-21 08:27:33 字数 1165 浏览 3 评论 0原文

I am trying to use a cloud run endpoint through GCP's Identity Aware Proxy and all of a sudden the IAP endpoint started throwing an error:

Invalid IAP credentials: Unable to parse JWT

I am using the extension_google_sign_in_as_googleapis_auth extension to create a Google client out of my existing Google/Firebase登录。

如果我直接使用浏览器访问API(直接使用相同的GCP凭据,则直接使用与使用该应用程序登录相同的GCP凭据),

我正在使用以下代码,该代码似乎正在连接到后端:我看到网络检查员开火,然后呼叫到端点。第一个是可以的,第二个错误是401,并且在体内的上面的消息。

getIAPAPI(String path) async {
  Uri uri;

  // make sure the Identity Aware Proxy is addressed authenticated
  var _signIn = GoogleSignIn(
    scopes: <String>[CloudIAPApi.cloudPlatformScope],
  );
  await _signIn.signInSilently();

  // create a GCP client
  final _client = await _signIn.authenticatedClient();

  print('fetching ${path} from api');
  try {
    uri = Uri.https('iapapi.example.com', path);
    var response = await _client?.get(uri);
    return response?.body;
  } catch (e) {
    // print errors and pass back an empty json result
    print(e);
    return "{}";
  }
}

我在代码中做错了什么?真的很奇怪的是,它似乎在一周前起作用。我在IAP控制台设置中看不到任何可能有所帮助的东西。

I am trying to use a cloud run endpoint through GCP's Identity Aware Proxy and all of a sudden the IAP endpoint started throwing an error:

Invalid IAP credentials: Unable to parse JWT

I am using the extension_google_sign_in_as_googleapis_auth extension to create a Google client out of my existing Google/Firebase login.

The IAP works fine if I access the api with the browser directly (using the same GCP credentials directly as I am logged into the app with)

I am using the following code, which seems to be connecting to the backend: I see the network inspector fire the CORS head and then the call to the endpoint. The first is fine, the second errors with a 401 and the message above in the body.

getIAPAPI(String path) async {
  Uri uri;

  // make sure the Identity Aware Proxy is addressed authenticated
  var _signIn = GoogleSignIn(
    scopes: <String>[CloudIAPApi.cloudPlatformScope],
  );
  await _signIn.signInSilently();

  // create a GCP client
  final _client = await _signIn.authenticatedClient();

  print('fetching ${path} from api');
  try {
    uri = Uri.https('iapapi.example.com', path);
    var response = await _client?.get(uri);
    return response?.body;
  } catch (e) {
    // print errors and pass back an empty json result
    print(e);
    return "{}";
  }
}

Am I doing something wrong in my code? The really weird thing is that it seemed to work a week ago. I don't see anything in the IAP console settings that could help either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文