Esempio n. 1
0
        const string c_scopes   = "Files.Read offline_access openid User.Read"; // offline_access is required to get a refresh token

        public static void OneDriveLoginAndAuthorize(string sourceName)
        {
            var oa = new OAuth(c_microsoftAuthorizatonEndpoint, c_microsoftTokenExchangeEndpoint, c_clientId);

            if (oa.Authorize(c_scopes))
            {
                // Store the refresh token in the Credential manager
                CredentialManager.Add(c_targetPrefix + sourceName, string.Empty, c_oneDrivePrefix + oa.Refresh_Token);
                Console.WriteLine($"Successfully created OneDrive named source: {sourceName}");
            }
            else
            {
                Console.WriteLine("OneDrive authorization failure.");
            }
        }