Проблема с авторизацией с помощью Gsuite API

#c# #google-oauth #google-workspace

#c# #google-oauth #google-workspace

Вопрос:

Я хочу создать пользователя с помощью Google API для своего домена. Я столкнулся с проблемой авторизации со следующим кодом. пожалуйста, предложите мне любой пример кода, если у вас есть. Я предоставляю свой код ниже, пожалуйста, помогите мне.

             string[] Scopes = { DirectoryService.Scope.AdminDirectoryUser };
            string ApplicationName = "App Name";
            UserCredential credential;

            using (var stream =
               new FileStream(Server.MapPath("..\")   credentials.json",FileMode.Open, FileAccess.Read))
            {

                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = Server.MapPath("..\")   "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Resu<
                Console.WriteLine("Credential file saved to: "   credPath);
            }

            // Create Directory API service.
            var service = new DirectoryService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });


            UsersResource usersResource = new UsersResource(service);


            Google.Apis.Admin.Directory.directory_v1.Data.User user = new Google.Apis.Admin.Directory.directory_v1.Data.User();
            UserName name = new UserName();
            name.FamilyName = register.ClientName;
            name.GivenName = register.ClientName;
            user.Name = name;
            user.Password = Password;
            user.PrimaryEmail = ConfigurationManager.AppSettings["CompanyEmailID"].ToString();

            var r = usersResource.Insert(user);
            r.Execute();
 

Комментарии:

1. Можете ли вы предоставить более подробную информацию о возникшей у вас проблеме?

2. Не удалось запустить браузер с » accounts.google.com/o/oauth2/v2 /… » для авторизации. Подробности см. Во внутреннем исключении.