小编sun*_*ro4的帖子

如何使用 Spotify 的 PKCE 实施授权码

编辑:澄清一下,获取授权代码按预期工作。这纯粹是用授权码交换令牌的步骤失败了。

我正在尝试使用 PKCE 流程实现授权代码,以便使用 Spotify API 进行身份验证。我知道有一些库可以实现这一点,但我真的想自己实现它。我所说的流程是这样的: https: //developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce 我我能够制作链接以将用户重定向到同意页面并获取授权代码。但是,当我尝试将此代码交换为令牌时,我收到一个 400 错误请求,其中包含消息“无效的 client_secret”。这让我相信 Spotify 假设我正在尝试使用常规授权代码流程,因为客户端密钥根本不是 PKCE 流程的一部分。我怀疑我对 code_verifier 或 code_challenge 的编码错误。我在 SO(How tocalculate PCKE's code_verifier?)上找到了这个答案,并将其翻译为 C#,为 Base64 编码的哈希产生相同的结果,但它仍然不起作用。

下面是我生成 code_verifier 和 code_challenge 的代码,以及发出交换代码请求的代码。

代码验证器:

private string GenerateNonce()
{
    const string chars = "abcdefghijklmnopqrstuvwxyz123456789";
    var random = new Random();
    var nonce = new char[100];
    for (int i = 0; i < nonce.Length; i++)
    {
        nonce[i] = chars[random.Next(chars.Length)];
    }
    return new string(nonce);
}
Run Code Online (Sandbox Code Playgroud)

代码挑战:

    private string GenerateCodeChallenge(string codeVerifier)
    {
        using …
Run Code Online (Sandbox Code Playgroud)

c# oauth spotify oauth-2.0

10
推荐指数
2
解决办法
1万
查看次数

将 IdentityServer4 快速入门部署到 Azure Web 应用程序在索引页上返回 404,但其他路由有效

我已经部署了一个从 identityserver4 的快速入门构建的项目(https://github.com/IdentityServer/IdentityServer4.Demo )。只要我在本地运行它,它就可以完美运行,但是当我将它部署到 Azure 时,索引页返回 404,但是当我手动转到其他路由(如“/account/login”)时,它们按预期工作。

我的 Startup.cs:

using System;
using System.Linq;
using System.Threading.Tasks;
using LunchBucks.Auth.Extensions;
using LunchBucksEncryption;
using LunchBucksEncryption.PasswordHashing;
using LunchBucksEncryption.SaltGeneration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace LunchBucks.Auth
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<ISaltGeneration, SaltGeneration>();
            services.AddTransient<IPasswordHashing, PasswordHashing>();
            services.AddTransient<IEncryptionManagement, EncryptionManagement>();
            services.AddMvc(); …
Run Code Online (Sandbox Code Playgroud)

azure azure-web-app-service asp.net-core identityserver4

5
推荐指数
1
解决办法
1387
查看次数

iOS WKWebview 中的 iFrame 内第三方 cookie 被阻止

我有一个用React开发的网站,我们在其中实现了通过iFrame登录第三方的功能。这在我们必须支持的所有浏览器中都按预期工作,但 iOS 上的 WKWebview 除外,它拒绝在 iFrame 中的另一个域上设置 cookie。我们有一个 React Native 应用程序,可以在这个 webview 中显示网页,所以我们必须支持它。通过大量的谷歌搜索,我发现了各种不再有效的解决方法,并最终出现在 Webkits 错误页面:https: //bugs.webkit.org/show_bug.cgi?id=204109 以及来自 SalesForce 的:https://help.salesforce.com/articleView ?id=000351155&language=en_US&type=1&mode=1 目前还不清楚这是否是实际上已修复,或者是否已重新引入(似乎已修复,因为它不适用于 iOS 13.3 设备)。有没有人有类似的经历,甚至更好,有潜在的解决方法?

提前致谢

webkit webview ios wkwebview react-native

5
推荐指数
1
解决办法
4214
查看次数