【问题标题】:How to get Firebase auth OAuthProvider to add additional scopes using OIDC provider如何让 Firebase auth OAuthProvider 使用 OIDC 提供程序添加其他范围
【发布时间】:2021-11-21 00:10:22
【问题描述】:

我已将自定义 OIDC 提供程序添加到我的 Google 身份平台。我可以成功地使用它进行身份验证,所以我知道这不是提供程序配置的问题,但是由于某种原因,当我尝试向令牌请求添加其他范围时,新范围不会出现在请求 url 中。在下面的代码块中,我看到 OAuthProvider 对象显示了我在请求 signInWithPopup 之前添加的其他范围。但是在此请求之后,当我验证收到的令牌时,它只有“oidc”范围,并且其他范围不会出现在弹出窗口的 URL 中。我是否遗漏了一些额外的步骤,或者其他范围不适用于 Firebase 身份验证中的自定义 OIDC 提供程序?

    let twitch = new firebase.auth.OAuthProvider('oidc.twitch');
    twitch.addScope('moderation:read');
    twitch.addScope('user:edit');
    console.log(twitch); // This shows the additional scopes requested
    const user = await this.auth.signInWithPopup(twitch); // This URL only shows the oidc scope
    console.log(user); // This user token does not have any additional scopes

在我必须自己进行身份验证之前,感谢任何帮助或确认。谢谢,

【问题讨论】:

标签: firebase firebase-authentication openid-connect angularfire google-identity


【解决方案1】:

使用重定向。

firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you the OAuth Access Token for that provider.
    var token = result.credential.accessToken;
  }
  var user = result.user;
});

// Start a sign in process for an unauthenticated user.
var provider = new firebase.auth.OAuthProvider('google.com');
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);

使用弹出窗口。

var provider = new firebase.auth.OAuthProvider('google.com');
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
 // This gives you the OAuth Access Token for that provider.
 var token = result.credential.accessToken;
 // The signed-in user info.
 var user = result.user;
});

【讨论】:

    【解决方案2】:

    Google 身份平台似乎只传递 openid-configuration scopes_supported 字段中定义的范围。但我认为,提供功能不应该是这样的

    {
     ...
     "scopes_supported": [
      "openid",
      "email",
      "profile"
     ],
     ...
    }

    例子:

    【讨论】:

      猜你喜欢
      • 2022-10-20
      • 1970-01-01
      • 2022-07-01
      • 2021-11-13
      • 1970-01-01
      • 2022-08-23
      • 2020-01-05
      • 2016-07-13
      • 1970-01-01
      相关资源
      最近更新 更多