要在 AWS Cognito 用户池上的自定义域中正确实现 /.well-known/openid-configuration,需要遵循以下步骤:
确保您的 Cognito 应用程序客户端设置为使用自定义域名。您可以将应用程序客户端的“Callback URL”和“Sign out URL”设置为自定义域中的 URL。
您需要将 AWS API Gateway 部署到自定义域名上。您可以使用您自己的域名或 Amazon 提供的 CloudFront 分发域名。如果您使用自己的域名,则需要在您的 DNS 记录中设置一些必要的 CNAME 记录。
在 AWS API Gateway 上启用映射到 Cognito 用户池的 Lambda 函数的 REST API。
要能够正确访问 /.well-known/openid-configuration,您需要在 Lambda 函数中添加以下代码片段:
exports.handler = (event, context, callback) => {
if(event.path === '/.well-known/openid-configuration') {
event.path = '/client/.well-known/openid-configuration';
}
// your code here
}
const config = {
region: ,
userPoolId:
};
const cisp = new AWS.CognitoIdentityServiceProvider(config);
exports.handler = (event, context, callback) => {
const path = event.path;
if(path === '/.well-known/openid-configuration') {
event.path = '/client' + path;
}
if(path === '/client/.well-known/openid-configuration') {
cisp.getOpenIdConfiguration({
UserPoolId:
}, (err, data) => {
if(err) {
callback(err);
} else {
callback(null, {