コード例 #1
0
    public DriveService AuthDrive(GoogleCloudConfig cloudConfig)
    {
        Log.Information("Initializing GoogleDrive client");
        var googleCred = "BotSettings.GoogleDriveAuth".SanitizeSlash();

        Log.Debug("GoogleDrive cred {0}", googleCred);
        using var stream = new FileStream(googleCred, FileMode.Open, FileAccess.Read);

        Log.Debug("Authorizing client..");
        var credPath = Path.Combine("Storage", "Common", "gdrive-auth-token-store").SanitizeSlash()
                       .EnsureDirectory();
        var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.FromStream(stream).Secrets,
            Scopes,
            "user",
            CancellationToken.None,
            new FileDataStore(credPath, true)).Result;

        Log.Debug("Credential saved to {0}", credPath);

        Log.Debug("Initializing Drive service");
        var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName       = AppName
        });

        Log.Information("Creating GoogleDrive client finish");

        return(service);
    }
コード例 #2
0
        public GoogleCloudPdfStorage(IOptions <GoogleCloudConfig> settings)
        {
            _settings = settings.Value;

            var googleAuthConfig = File.ReadAllText(_settings.GoogleAuthFile);

            _storageClient = StorageClient.Create(credential: GoogleCredential.FromJson(googleAuthConfig).CreateScoped(new List <string>
            {
                StorageService.Scope.DevstorageFullControl
            }));
        }
コード例 #3
0
        public static void AddCloudServicesDb(this IServiceCollection services, GoogleCloudConfig googleCloudConfig, MongoDbConfig mongoDbConfig)
        {
            services.AddScoped(s => new MongoClient(mongoDbConfig.ConnectionString));

            StorageClientBuilder storageClientBuilder = new StorageClientBuilder
            {
                CredentialsPath = googleCloudConfig.KeyPath
            };

            services.AddScoped(s => storageClientBuilder.Build());
        }
コード例 #4
0
 public ServiceAccountService(
     IOptionsSnapshot <GoogleCloudConfig> googleCloudConfig
     )
 {
     _googleCloudConfig = googleCloudConfig.Value;
 }
コード例 #5
0
 /// <summary>
 /// Constructor for GoogleApiService
 /// </summary>
 /// <param name="googleCloudConfig"></param>
 public GoogleApiService(
     IOptionsSnapshot <GoogleCloudConfig> googleCloudConfig
     )
 {
     _googleCloudConfig = googleCloudConfig.Value;
 }