Google auth - 有什么方法可以在重定向中发回自定义数据 URL?

Google auth - any way to have custom data sent back in redirect URL?

我正在通过 Google 实现单点登录到我的网站,它工作正常,但是:我需要它来支持网站的各种实例。

这是一个问题,因为 Google 似乎不支持重定向 URL 中的任何类型的动态。来自 docs 关于重定向 URLs:

Determines where the API server redirects the user after the user completes the authorization flow. The value must exactly match one of the authorized redirect URIs for the OAuth 2.0 client, which you configured in the API Console.

至少可以说这很烦人;没有通配符,没有查询字符串变体 - 必须与您存储在控制台中的值完全匹配。

所以我的问题是: 有谁知道有什么方法可以将 Google 的身份验证服务告诉 return 自定义数据 附加 到重定向 URL?

我在想

$google->setRedirectUri('http://example.com/foo');

//pseudo code...
$google->setCustomRedirectData([
    'foo' => 'bar'
]);

...这将生成

http://example.com/foo?code=...&other_google_params=...&foo=bar

有什么办法吗,或者我别无选择,只能手动指定每个重定向 URL?

我们为此使用 state 参数。在我们的例子中,我们只需要存储少量数据(用户来自我们的通配符子域或自定义域)并且它非常有效。

它的格式由您决定。我们将一些(非敏感的)JSON 进行 base64 编码。