Esempio n. 1
0
        /// <summary>
        /// Static method that creates a new object of PGDrive class and authenticates user using OAuth2.0 authorization
        /// </summary>
        /// <param name="ConfigOAuthDriveName">Name of element in ApiKeyDrives collection of PGDrive section in your config</param>
        /// <param name="scopes"> USE PGScopes static class,
        /// combine scopes using method And in scope objects.
        /// Scopes provides permissions to use your drive.
        /// </param>
        /// <param name="reCreateOAuthToken">Recreates an access token for current drive if you want to change the scopes</param>
        /// <exception cref="NullReferenceException">Throws if elemtent of OAuthDrives config collection with such name wasn't founded</exception>
        public static PGDrive GetOAuthDrive(string ConfigOAuthDriveName, PGScope scopes = null, bool reCreateOAuthToken = false)
        {
            PGDrive newDrive = new PGDrive();

            newDrive.Auth         = new Auth();
            newDrive.driveService = newDrive.Auth.GetOAuthDrive(ConfigOAuthDriveName, scopes, reCreateOAuthToken);
            newDrive.InitializeModules();
            return(newDrive);
        }
Esempio n. 2
0
        public DriveService GetOAuthDrive(string ConfigOAuthDriveName, PGScope scopes = null, bool recreateOAuthToken = false)
        {
            OAuthGDriveElement oAuth = PGDriveConfig.GetOAuthElement(ConfigOAuthDriveName);

            if (oAuth != null)
            {
                List <string> scopesList = new List <string>();
                if (scopes != null)
                {
                    scopesList = scopes.Scopes;
                }
                ApplicationName = oAuth.ApplicationName;
                return(GetOAuthDriveService(oAuth.ApplicationName, oAuth.ClientSecretPath, scopesList.ToArray(), recreateOAuthToken));
            }
            throw new NullReferenceException("There is no drive with such name in OAuthDrives collection of PGDrive config section");
        }