public DeviceFlowOAuth2 authorize(string client_id, string client_secret, string scope) { string user_code = string.Empty; string device_code = string.Empty; string verification_url = string.Empty; int interval = 5; DeviceFlowOAuth2 oauth = new DeviceFlowOAuth2(client_id, client_secret, scope); oauth.getUserCode(out user_code, out device_code, out verification_url, out interval); ConsoleWrite("Before you can start using the plugin, you must grant it access to your Google Drive account."); ConsoleWrite("Please visit the verification url " + verification_url + ", and enter user code: " + user_code); int iterations = 10; while (iterations-- > 0) { oauth.getAccessAndRefreshTokens(device_code); if (oauth.state.Equals(DeviceFlowOAuth2.APIState.AccessDenied)) throw new OAuth2Exception("Access to the Google Document List API has been denied"); else if (oauth.state.Equals(DeviceFlowOAuth2.APIState.AccessPending)) { //ConsoleWrite("Waiting for user to grant application access to the Google Document List API ... "); } else if (oauth.state.Equals(DeviceFlowOAuth2.APIState.AccessGranted)) { ConsoleWrite("Access to the Google Document List API has been granted"); break; } Thread.Sleep(interval * 1000); } if (iterations == -1 && oauth.state.Equals(DeviceFlowOAuth2.APIState.AccessPending)) throw new OAuth2Exception("Timeout expired while waiting for user to grant application access to the Google Document List API"); oauth.refreshAccessToken(); return oauth; }
public DeviceFlowOAuth2 authorize(string client_id, string client_secret, string scope, string access_token, string refresh_token) { DeviceFlowOAuth2 oauth = new DeviceFlowOAuth2(client_id, client_secret, scope); oauth.access_token = access_token; oauth.refresh_token = refresh_token; oauth.refreshAccessToken(); return oauth; }