最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Blazor server app with Google Web Authorization error - Stack Overflow

programmeradmin4浏览0评论

The integration of YouTubeService in Blazor server application always results in Error 400: redirect_uri_mismatch. The Google Cloud configuration is set for new web application with both Authorised JavaScript origins and Authorised redirect URIs set to https://localhost:5001. How, to setup redirect url to resolve the issue? Is there a need to create dedicated page in blazor app for redirect url. Below is the code with relevant issue.

public class YouTubeApiService
{
    private YouTubeService _youtubeService;
    private readonly string[] Scopes = { YouTubeService.Scope.YoutubeReadonly };
   
    public YouTubeApiService(IConfiguration configuration)
    {
        _clientSecrets = new ClientSecrets
        {
            ClientId = configuration["xxxxxxxx"],
            ClientSecret = onfiguration["xxxxxxxx"]
        };
    }

    public async Task AuthenticateAsync()
    {
        using var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read);

        // Here new tab is created with  Error 400
        var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.FromStream(stream).Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore("YouTubeOAuthToken"),
            new LocalServerCodeReceiver ()); 

        _youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "blabal"
        });
    }
}
发布评论

评论列表(0)

  1. 暂无评论