public ActionResult AuthorizationCheck(GoogleAPIAccess model) { if (model.AccessCode == null) { //////////////////////////////////////////////////////////////////////////// // STEP 3: Get the Authorization URL //////////////////////////////////////////////////////////////////////////// // Get the authorization url. The user of your application must visit // this url in order to authorize with Google. If you are building a // browser-based application, you can redirect the user to the authorization // url. model._RedirectURIs = "urn:ietf:wg:oauth:2.0:oob"; ViewData["authorizationUrl"] = OAuthUtil.CreateOAuth2AuthorizationUrl(model); model._RedirectURIs = Url.Action("AuthorizationCheckAuto", "Configuration", new { }, "http"); ViewData["authorizationUrlAuto"] = OAuthUtil.CreateOAuth2AuthorizationUrl(model); return(View(model)); } //////////////////////////////////////////////////////////////////////////// // STEP 4: Get the Access Token //////////////////////////////////////////////////////////////////////////// // Once the user authorizes with Google, the request token can be exchanged // for a long-lived access token. If you are building a browser-based // application, you should parse the incoming request token from the url and // set it in OAuthParameters before calling GetAccessToken(). model._RedirectURIs = "urn:ietf:wg:oauth:2.0:oob"; OAuthUtil.GetAccessToken(model); return(RedirectToAction("Index", model)); }
public bool ShowAuthorizationDialog(bool isModal) { logger.Debug("ShowAuthorizationDialog {0}", isModal); string sAuthorizationURL = OAuthUtil.CreateOAuth2AuthorizationUrl(AuthParams); GoogleAuthForm fAuthForm = new GoogleAuthForm(); fAuthForm.Url = sAuthorizationURL; if (isModal) { fAuthForm.ShowDialog(); } else { fAuthForm.Show(); } AuthResult arAuthResult = fAuthForm.Result ?? new AuthResult() { Result = ResultType.Denied, Value = string.Empty }; logger.Info("Authorization Result={0}, Value={1}", arAuthResult.Result, arAuthResult.Value); if (arAuthResult.Result == ResultType.Success) { AuthParams.AccessCode = arAuthResult.Value; OAuthUtil.GetAccessToken(AuthParams); SaveAuthParams(); return(true); } return(false); }
/// <summary> /// This console application demonstrates the usage of OAuth 2.0 with the Google Apps APIs. /// </summary> /// <param name="args">Command-line arguments: args[0] is /// the client ID, args[1] is the client secret, args[2] is domain name. /// </param> public static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Syntax: OAuth2Demo <client_id> <client_secret> <domain>"); } else { clientId = args[0]; clientSecret = args[1]; domain = args[2]; OAuth2Parameters parameters = new OAuth2Parameters() { ClientId = clientId, ClientSecret = clientSecret, RedirectUri = redirectUri, Scope = scopes }; string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Console.WriteLine("Authorize URI: " + url); parameters.AccessCode = Console.ReadLine(); OAuthUtil.GetAccessToken(parameters); // Testing OAuth 2.0 with a Request-based library RunContactsSample(parameters); // Testing OAuth 2.0 with a Service-based library RunGroupsSample(parameters, domain); } }
public static OAuth2Parameters Authorize() { var parameters = new OAuth2Parameters { ClientId = ConfigurationManager.AppSettings.Get("Google-ClientID"), ClientSecret = ConfigurationManager.AppSettings.Get("Google-ClientSecret"), Scope = "https://spreadsheets.google.com/feeds", RedirectUri = "urn:ietf:wg:oauth:2.0:oob" //installed applications }; var authUri = new Uri(OAuthUtil.CreateOAuth2AuthorizationUrl(parameters)); using (var login = new GoogleLogin(authUri)) { if (login.ShowDialog() != DialogResult.OK) { return(null); } parameters.AccessCode = login.AccessCode; } try { OAuthUtil.GetAccessToken(parameters); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } return(parameters); }
public void newMethod() { string CLIENT_ID = "599831794378-85d0ai95jak2mobjp1h0p7n0d2bua8n3.apps.googleusercontent.com"; string CLIENT_SECRET = "AlYRvFcwAILGyTMwYZz2veoJ"; string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds"; string REDIRECT_URI = "http://localhost:53278/uploadpage.aspx";// "urn:ietf:wg:oauth:2.0:oob"; OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; Session["para"] = parameters; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Response.Redirect(authorizationUrl); }
public JsonResult GetGmailAuthorizationCode(bool isTask, bool isContact) { string scope = string.Empty; if (isTask) { scope = "https://www.googleapis.com/auth/tasks"; } else if (isContact) { scope = "https://www.googleapis.com/auth/contacts.readonly"; } else { scope = "https://www.googleapis.com/auth/calendar"; } OAuth2Parameters parameters = new OAuth2Parameters() { //Client ClientId = ClientCredentials.ClientID, ClientSecret = ClientCredentials.ClientSecret, RedirectUri = "urn:ietf:wg:oauth:2.0:oob", // Scope = "https://www.googleapis.com/auth/tasks", Scope = scope, }; //User clicks this auth url and will then be sent to your redirect url with a code parameter var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); //string retError = ""; string retJSON = ""; retJSON = JsonConvert.SerializeObject(authorizationUrl); return(Json(retJSON, JsonRequestBehavior.AllowGet)); }
public static void InitAuthenticate() { string clientId = GoogleDataSettings.Instance.OAuth2Data.client_id; string clientSecret = GoogleDataSettings.Instance.OAuth2Data.client_secret; string accessCode = GoogleDataSettings.Instance._AccessCode; // OAuth2Parameters holds all the parameters related to OAuth 2.0. OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = clientId; parameters.ClientSecret = clientSecret; parameters.RedirectUri = REDIRECT_URI; // Retrieves the Authorization URL parameters.Scope = SCOPE; parameters.AccessType = "offline"; // IMPORTANT and was missing in the original parameters.TokenType = TOKEN_TYPE; // IMPORTANT and was missing in the original string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Debug.Log(authorizationUrl); Debug.Log("Please visit the URL above to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); parameters.AccessCode = accessCode; if (string.IsNullOrEmpty(parameters.AccessCode)) { Application.OpenURL(authorizationUrl); } }
void GetAccessCode() { // OAuth2Parameters holds all the parameters related to OAuth 2.0. OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; // Get the Authorization URL parameters.Scope = SCOPE; parameters.AccessType = "offline"; // IMPORTANT and was missing in the original parameters.TokenType = TOKEN_TYPE; // IMPORTANT and was missing in the original // Authorization url. string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Debug.Log(authorizationUrl); Debug.Log("Please visit the URL above to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); parameters.AccessCode = accessCode; if (parameters.AccessCode == "") { Debug.LogWarning("Access code is blank!"); EditorUtility.ClearProgressBar(); Application.OpenURL(authorizationUrl); return; } Debug.Log("Get access token."); // Get the Access Token try{ OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; string refreshToken = parameters.RefreshToken; Debug.Log("OAuth Access Token: " + accessToken + "\n"); ACCESS_TOKEN = accessToken; Debug.Log("OAuth Refresh Token: " + refreshToken + "\n"); REFRESH_TOKEN = refreshToken; PlayerPrefs.SetString(PREF_ACCESS_CODE, accessCode); PlayerPrefs.Save(); DownloadToJson(); } catch (System.Exception e) { Debug.LogError(e.ToString()); EditorUtility.ClearProgressBar(); Application.OpenURL(authorizationUrl); return; } }
public static void Authorize(OAuth2Parameters parameters) { //parameters.RedirectUri = "urn:ietf:wg:oauth:2.0:oob"; parameters.RedirectUri = "http://localhost:8080"; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); var listener = new HttpListener(); listener.Prefixes.Add("http://localhost:8080/"); listener.Start(); var contextAsync = listener.GetContextAsync(); System.Diagnostics.Process.Start(authorizationUrl); contextAsync.Wait(); parameters.AccessCode = contextAsync.Result.Request.QueryString["code"]; HttpListenerResponse response = contextAsync.Result.Response; // Construct a response. string responseString = "<HTML><head><script>window.open('', '_self', ''); /* bug fix chrome*/ window.close();</script></head></HTML>"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); listener.Stop(); //http://stackoverflow.com/questions/12077455/gdata-oauthutil-getaccesstoken-does-not-return-a-refresh-token-value OAuthUtil.GetAccessToken(parameters); }
public static string getAuthorizationURL(string clientId, string clientSecret) { OAuth2Parameters parameters = getOAuth2Parameters(clientId, clientSecret); string authURL = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(authURL); }
private void NGAMail() { //One time Initialization across the entire session required //if (authorizationUrl == null || authorizationUrl == string.Empty) //{ string CLIENT_ID = "284081438460-sdg3dn9tt80huceeb9v4n833n97lmtlu.apps.googleusercontent.com"; string CLIENT_SECRET = "HNb2txJ2QpK0amd4IR7HAxZK"; string SCOPE = "https://spreadsheets.google.com/feeds"; string REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"; OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); if (InputBox("AccessCode", "Input AccessCode from Browser", ref authorizationUrl) == DialogResult.OK) { parameters.AccessCode = authorizationUrl; } else { MessageBox.Show("Invallid Access Code!"); btnConnectJenkins.Enabled = true; return; } OAuthUtil.GetAccessToken(parameters); GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "AlmJenkinsIntegration", parameters); spreadsheetsService.RequestFactory = requestFactory; //} }
public IAccountSettings TestAccount(IAccountSettings accountnForTest) { parameters.ClientId = Constants.googleSheetsCLIENT_ID; parameters.ClientSecret = Constants.googleSheetsCLIENT_SECRET; parameters.RedirectUri = Constants.googleSheetsREDIRECT_URI; parameters.Scope = Constants.googleSheetsSCOPE; GoogleSheetsAccountSettings accountForTestGS = (GoogleSheetsAccountSettings)accountnForTest; GoogleSheetsAccountToken tokenForTest = accountForTestGS.Tokens.First(); Boolean result = false; if (tokenForTest != null) { foreach (GoogleSheetsAccountToken gast in accountForTestGS.Tokens) { if (gast.TokenName == "GetNewToken") { string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); gast.RefreshToken = authorizationUrl; } else if (gast.TokenName == "EnterAccessToken") { parameters.AccessToken = gast.RefreshToken; parameters.AccessCode = gast.RefreshToken; OAuthUtil.GetAccessToken(parameters); gast.RefreshToken = parameters.RefreshToken; } else if (gast.TokenName == "UseSaveToken") { parameters.AccessToken = gast.RefreshToken; parameters.AccessCode = gast.RefreshToken; parameters.RefreshToken = gast.RefreshToken; OAuthUtil.RefreshAccessToken(parameters); } else if (gast.TokenName == "CheckFileName") { parameters.AccessToken = accountForTestGS.Tokens[0].RefreshToken; parameters.AccessCode = accountForTestGS.Tokens[0].RefreshToken; parameters.RefreshToken = accountForTestGS.Tokens[0].RefreshToken; bool result2; result2 = CheckFileGS(gast.RefreshToken, accountForTestGS); if (!result2) { gast.RefreshToken = "This file does not exist"; } else { gast.RefreshToken = "OK"; } } } result = true; } accountForTestGS.TestResult = result; return(accountForTestGS); }
public void OpenAccessCodeURL() { parameters = GetRawOAuth2Parameters(); var authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); State = AuthenticationState.WaitingAccessCode; Application.OpenURL(authorizationUrl); }
public string GetAuthURL() { OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = Config.CLIENT_ID; parameters.ClientSecret = Config.CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; return(OAuthUtil.CreateOAuth2AuthorizationUrl(parameters)); }
private GoogleProvider() { LoggerProvider.Instance.Logger.Debug("Class GoogleProvider created and fill data for OAuth 2.0"); OAuth20.ClientId = clientID; OAuth20.ClientSecret = clientSecret; OAuth20.RedirectUri = redirectUri; OAuth20.Scope = scopes; GoogleIsAuthorize = false; GoogleAuthorizeRequestUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(OAuth20); }
private void setAuthorizationUrl() { string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oAuth2Parameters); Console.WriteLine(authorizationUrl); Console.WriteLine("Please visit the URL above to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); oAuth2Parameters.AccessCode = Console.ReadLine(); }
private async Task <DialogResult> GetGoogleService(Action <string, string> setPath) { if (_googleDocGenerator == null) { OAuth2Parameters parameters = new OAuth2Parameters { ClientId = "261863669828-1k61kiqfjcci0psjr5e00vcpnsnllnug.apps.googleusercontent.com", ClientSecret = "IDtucbpfYi3C7zWxsJUX4HbV", RedirectUri = "urn:ietf:wg:oauth:2.0:oob", Scope = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds", ResponseType = "code" }; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); var browserDialog = new BrowserDialog(TimeSpan.FromSeconds(30), new Uri(authorizationUrl)); try { if (await browserDialog.ShowAsync(code => parameters.AccessCode = code) != DialogResult.OK) { return(DialogResult.Cancel); } } catch (Exception e) { ShowDialogWindow(DialogIcon.Critical, DialogRes.Exception, e.ToString()); throw; } OAuthUtil.GetAccessToken(parameters); _googleOAuth2Parameters = parameters; var service = new SpreadsheetsService("MySpreadsheetIntegration-v1") { RequestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters) }; _googleDocGenerator = new GoogleDocGenerator(service); } else { if (_googleOAuth2Parameters.TokenExpiry <= DateTime.Now) { OAuthUtil.RefreshAccessToken(_googleOAuth2Parameters); } } SelectGoogleDocumentDialog selectDocumentDialog = new SelectGoogleDocumentDialog(_showDialogAction, _googleDocGenerator); DialogResult dialogResult = await selectDocumentDialog.ShowAsync(setPath); return(dialogResult); }
public void InitAuthenticate() { OAuth2Parameters parameters = GetParameters(); string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Debug.Log(authorizationUrl); Debug.Log("Please visit the URL above to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); Application.OpenURL(authorizationUrl); }
public LoginWindow() { InitializeComponent(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); LoginBrowser.Source = new Uri(authorizationUrl, UriKind.Absolute); }
private void googleDriveToolStripMenuItem_Click(object sender, EventArgs e) { if (_Gmail == null || _Gpass == null) { ToErrorLog("Отсутствие данных", "Авторизация Google", "Ключ не содержал данных!"); return; } parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; //////////////////////////////////////////////////////////////////////////// // STEP 3: Get the Authorization URL //////////////////////////////////////////////////////////////////////////// // Set the scope for this particular service. parameters.Scope = SCOPE; // Get the authorization url. The user of your application must visit // this url in order to authorize with Google. If you are building a // browser-based application, you can redirect the user to the authorization // url. string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); //System.Diagnostics.Process.Start(authorizationUrl); Authentication auth = new Authentication(); auth.URL = authorizationUrl; auth.Gpass = _Gpass; auth.Gmail = _Gmail; auth.ShowDialog(); if (auth.Key != null) { parameters.AccessCode = auth.Key; OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters); service = new SpreadsheetsService("MySpreadsheetIntegration-v1"); service.RequestFactory = requestFactory; GooglePicture.Image = Properties.Resources.googleDrive as Bitmap; GoogleToolTip.SetToolTip(this.GooglePicture, "Доступ к Google Disk\nразрешен."); } else { MessageBox.Show("Вход не выполнен", "Google Service Access", MessageBoxButtons.OK, MessageBoxIcon.Error); } ToLog("Авторизация Google", string.Format(auth.Info)); auth.Close(); }
public static String getAuthCode(OAuth2Parameters parameters) { MessageBox.Show("About to launch a browser to get the Authorization Code. Please copy and paste the code given into the applciation."); string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); logger.Debug("Auth URL: " + authorizationUrl); Process.Start(authorizationUrl); frmAuthCode frm = new frmAuthCode(); frm.ShowDialog(); return(frm.txtAuthCode.Text); }
public void GetAccessCode() { OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Application.OpenURL(authorizationUrl); }
public string GetAuthURL() { if (config == null) { config = (GoogleSheetsToUnityConfig)UnityEngine.Resources.Load("GSTU_Config"); } OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = config.CLIENT_ID; parameters.ClientSecret = config.CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; return(OAuthUtil.CreateOAuth2AuthorizationUrl(parameters)); }
public static GOAuth2RequestFactory RefreshAuthenticate() { OAuth2Parameters parameters = new OAuth2Parameters() { RefreshToken = ACCESS_TOKEN, AccessToken = REFRESH_TOKEN, ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, Scope = "https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds", AccessType = "offline", TokenType = "refresh" }; string authUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(new GOAuth2RequestFactory("spreadsheet", "MySpreadsheetIntegration-v1", parameters)); }
public GOAuth2RequestFactory RefreshAuthenticate() { OAuth2Parameters parameters = new OAuth2Parameters() { RefreshToken = _RefreshToken, AccessToken = _AccessToken, ClientId = _ClientId, ClientSecret = _ClientSecret, Scope = "https://spreadsheets.google.com/feeds", //https://www.googleapis.com/auth/drive AccessType = "offline", TokenType = "refresh" }; string authUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(new GOAuth2RequestFactory("spreadsheet", "nestcoworkingspace", parameters)); }
private void AskAccessCode() { // Ask to get the authorization code. Give the URL and ask for the code. string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oauthParams); Console.WriteLine("Please open the following link in a browser and authorize"); Console.WriteLine("yourself on the webpage. Once that is complete, type"); Console.WriteLine("your access code and press Enter to continue."); Console.WriteLine(authorizationUrl); Console.Write("Access code: "); oauthParams.AccessCode = Console.ReadLine(); Console.WriteLine("-----------------------------------------"); Console.WriteLine(); OAuthUtil.GetAccessToken(oauthParams); }
static void Main(string[] args) { string CLIENT_ID = "YOUR_CLIENT_ID"; string CLIENT_SECRET = "YOUR_CLIENT_SECRET"; string SCOPE = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds"; string REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"; OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); MessageBox.Show(authorizationUrl); Console.WriteLine("Please visit the URL in the message box to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); parameters.AccessCode = Console.ReadLine(); OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; Console.WriteLine("OAuth Access Token: " + accessToken); GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters); SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1"); service.RequestFactory = requestFactory; SpreadsheetQuery query = new SpreadsheetQuery(); SpreadsheetFeed feed = service.Query(query); // Iterate through all of the spreadsheets returned foreach (SpreadsheetEntry entry in feed.Entries) { // Print the title of this spreadsheet to the screen Console.WriteLine(entry.Title.Text); } Console.ReadLine(); }
/// <summary> /// Gets the Google service URL for fetching access code. /// </summary> /// <param name="viewName">The view name of the service to run.</param> /// <returns></returns> public static string GetServiceURL(string viewName) { //Initializing OAuthParameters for accessing the Google service(s). OAuth2Parameters parameters = new OAuth2Parameters() { ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, RedirectUri = REDIRECT_URI, Scope = viewName == "Drive" ? DRIVE_SCOPE : CONTACTS_SCOPE, State = STATE, AccessType = ACCESS_TYPE }; //Fetching URL for viewing the service's access code. string authUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(authUrl); }
public static void GetRefreshToken(GoogleParams p) { OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = p.clientId; parameters.ClientSecret = p.clientSecret; parameters.RedirectUri = p.redirectUri; parameters.Scope = p.scope; string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); Console.WriteLine(authorizationUrl); Console.WriteLine("Please visit the URL above to authorize your OAuth " + "request token. Once that is complete, type in your access code to " + "continue..."); parameters.AccessCode = Console.ReadLine(); OAuthUtil.GetAccessToken(parameters); Console.WriteLine("OAuth Refresh Token: \n" + parameters.RefreshToken); }
private static string CreateAuthorizationUrl(string returnUrl, string scope, string state, string accessType) { OAuth2Parameters parameters = CreateAuthorizationParameters(scope); parameters.RedirectUri = returnUrl; if (!string.IsNullOrEmpty(accessType)) { parameters.AccessType = accessType; } if (!string.IsNullOrEmpty(state)) { parameters.State = System.Web.HttpUtility.UrlEncode(state); } string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(url); }