Wie richte ich Google Anmeldung ohne Identität ein?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie richte ich Google Anmeldung ohne Identität ein?

Post by Anonymous »

Ich habe ein Beispiel -Blazor -Projekt ohne Identität erstellt und versuchte, Google hinzuzufügen, aber ich erhalte diese Ausnahme immer wieder: < /p>

AuthentifizierungFailException: Der OATH -Zustand fehlte oder ungültig. /> Dies ist alles mein Code: < /p>
Program.cs

Code: Select all

using GoogleOAuth.Components;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.Google;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(options =>
{
options.ClientId = "...";
options.ClientSecret = "...";
});

builder.Services.AddAuthorization();

// Add services to the container.
builder.Services.AddRazorComponents();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseAuthentication();
app.UseAuthorization();

app.UseAntiforgery();

app.MapStaticAssets();
app.MapRazorComponents();

app.Run();
Home.razor

Code: Select all

@page "/"



data-client_id="..."
data-login_uri="https://localhost:7091/signin-google"
data-auto_prompt="false" class="rounded-xl">




Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post