Используя этот проект в качестве основы
https://github.com/googleapis/google-ap ... ationTests
наш проект реализует следующее:
Создал проект и получил client_id и секретный ключ в нашей учетной записи Google.
Включает Google.Apis.Auth Пакеты .AspNetCore3 и Google.Apis.Drive.v3
Код: Выделить всё
Код: Выделить всё
public void ConfigureServices(IServiceCollection services)
{
...
// This configures Google.Apis.Auth.AspNetCore3 for use in this app.
services
.AddAuthentication(o =>
{
// This forces challenge results to be handled by Google OpenID Handler, so there's no
// need to add an AccountController that emits challenges for Login.
o.DefaultChallengeScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
// This forces forbid results to be handled by Google OpenID Handler, which checks if
// extra scopes are required and does automatic incremental auth.
o.DefaultForbidScheme = GoogleOpenIdConnectDefaults.AuthenticationScheme;
// Default scheme that will handle everything else.
// Once a user is authenticated, the OAuth2 token info is stored in cookies.
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogleOpenIdConnect(options =>
{
options.ClientId = "
Подробнее здесь: [url]https://stackoverflow.com/questions/65794417/why-is-google-drive-api-call-from-net-core-3-1-not-authenticated[/url]
Мобильная версия