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 static void FinishAuthenticate(GoogleSettings googleSettings) { try { OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = googleSettings.authInfo.client_id; parameters.ClientSecret = googleSettings.authInfo.client_secret; parameters.RedirectUri = googleSettings.authInfo.GetRedirectURI(); parameters.Scope = SCOPE; parameters.AccessType = "offline"; // IMPORTANT parameters.TokenType = TOKEN_TYPE; // IMPORTANT parameters.AccessCode = googleSettings.accessCode; OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; string refreshToken = parameters.RefreshToken; //Debug.Log("OAuth Access Token: " + accessToken + "\n"); //Debug.Log("OAuth Refresh Token: " + refreshToken + "\n"); googleSettings.refreshToken = refreshToken; googleSettings.accessToken = accessToken; } catch (Exception e) { // To display the error message with EditorGUI.Dialogue, we throw it again. throw new Exception(e.Message); } }
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); } }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { OAuth2Parameters parameters_lst = oauthcredentials(); GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "Fusion-SpreadSheet", parameters_lst); SpreadsheetsService service = new SpreadsheetsService("Fusion-SpreadSheet"); service.RequestFactory = requestFactory; SpreadsheetQuery query = new SpreadsheetQuery(); // Make a request to the API and get all spreadsheets. SpreadsheetFeed feed = service.Query(query); // Iterate through all of the spreadsheets returned ddlexcellst.Items.Add("------------------- Select------------------"); foreach (SpreadsheetEntry entry in feed.Entries) { // Print the title of this spreadsheet to the screen //Response.Write(entry.Title.Text); ddlexcellst.Items.Add(entry.Title.Text); } } } catch (Exception) { Response.Redirect("Default.aspx"); } }
public bool SignIn(string accessCode) { try { parameters = GetRawOAuth2Parameters(); parameters.AccessCode = accessCode; // 同期WebRequest通信が中で走る. OAuthUtil.GetAccessToken(parameters); SpreadsheetConnectorPrefs.accessTokenKey = parameters.AccessToken; SpreadsheetConnectorPrefs.refreshTokenKey = parameters.RefreshToken; SpreadsheetConnectorPrefs.tokenExpiryKey = parameters.TokenExpiry.ToString(); service = CreateService(parameters); State = AuthenticationState.SignIn; return(true); } catch (Exception ex) { Debug.LogException(ex); SignOut(); return(false); } }
//----- method ----- public void Initialize(SpreadsheetConfig config) { this.config = config; System.Net.ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true; DateTime dt; parameters = GetRawOAuth2Parameters(); parameters.AccessToken = SpreadsheetConnectorPrefs.accessTokenKey; parameters.RefreshToken = SpreadsheetConnectorPrefs.refreshTokenKey; if (DateTime.TryParse(SpreadsheetConnectorPrefs.tokenExpiryKey, out dt)) { parameters.TokenExpiry = dt; } if (!string.IsNullOrEmpty(parameters.AccessToken)) { service = CreateService(parameters); State = AuthenticationState.SignIn; } else { State = AuthenticationState.SignOut; } }
public ActionResult SubmitAuthorize(string code) { string REDIRECT_URI = "http://localhost:11551" + Url.Action("SubmitAuthorize", new { controller = "photoshop", area = "admin" }); OAuth2Parameters parameters = new OAuth2Parameters { ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET, RedirectUri = REDIRECT_URI, Scope = SCOPE, AccessCode = code }; OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; var shet = _context.GoogleSheetsSync.Find(Guid.Empty); if (shet == null) { shet = new GoogleSheetsSync() { ID = Guid.Empty, Token = accessToken, RefreshToken = parameters.RefreshToken }; _context.GoogleSheetsSync.Add(shet); } else { shet.Token = accessToken; shet.RefreshToken = parameters.RefreshToken; } _context.SaveChanges(); return(RedirectToAction("Index")); }
public static string getAuthorizationURL(string clientId, string clientSecret) { OAuth2Parameters parameters = getOAuth2Parameters(clientId, clientSecret); string authURL = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); return(authURL); }
static void auth() { //string[] Scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly" }; // view your basic profile info. // Requesting access to Contacts API and Groups Provisioning API string[] Scopes = new string[] { "https://www.googleapis.com/auth/contacts.readonly", "https://www.google.com/m8/feeds/", "https://apps-apis.google.com/a/feeds/groups/" }; // view your basic profile info. try { //string clientId = "xxxxxx.apps.googleusercontent.com"; //string clientSecret = "xxxxx"; ////// Use the current Google .net client library to get the Oauth2 stuff. ////UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } //// , Scopes //// , "test" //// , CancellationToken.None //// , new FileDataStore("test")).Result; UserCredential credential; using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } ////// Create Gmail API service. ////var service = new GmailService(new BaseClientService.Initializer() ////{ //// HttpClientInitializer = credential, //// ApplicationName = ApplicationName, ////}); // Translate the Oauth permissions to something the old client libray can read OAuth2Parameters parameters = new OAuth2Parameters(); parameters.AccessToken = credential.Token.AccessToken; parameters.RefreshToken = credential.Token.RefreshToken; RunContactsSample(parameters); Console.ReadLine(); } catch (Exception ex) { Console.ReadLine(); } Console.ReadLine(); }
/// <summary> /// Initilize sheets API with saved token /// </summary> public void Initilize() { PermissiveCert.Instate(); RefreshToken = EditorPrefs.GetString("Datablocks_RefreshToken"); AccessToken = EditorPrefs.GetString("Datablocks_AccessToken"); Service = new SpreadsheetsService("Datablocks for Unity"); // OAuth2Parameters holds all the parameters related to OAuth 2.0. oAuthParameters = new OAuth2Parameters(); // Set your OAuth 2.0 Client Id (which you can register at oAuthParameters.ClientId = CLIENT_ID; // Set your OAuth 2.0 Client Secret, which can be obtained at oAuthParameters.ClientSecret = CLIENT_SECRET; // Set your Redirect URI, which can be registered at oAuthParameters.RedirectUri = REDIRECT_URI; // Set the scope for this particular service. oAuthParameters.Scope = SCOPE; if (!string.IsNullOrEmpty(RefreshToken)) { oAuthParameters.RefreshToken = RefreshToken; oAuthParameters.AccessToken = AccessToken; var requestFactory = new GOAuth2RequestFactory(null, "Datablocks for Unity", oAuthParameters); Service.RequestFactory = requestFactory; } }
private void setOAuth2ParametersWithConfigSettings() { oAuth2Parameters = new OAuth2Parameters(); oAuth2Parameters.ClientId = ConfigurationManager.AppSettings["GoogleClientID"]; oAuth2Parameters.ClientSecret = ConfigurationManager.AppSettings["GoogleClientSecret"]; oAuth2Parameters.Scope = ConfigurationManager.AppSettings["GoogleScope"]; }
public static void auth() { string clientId = "160518507662-5i1uj2epd4nptippu55c7l9ohmco9c00.apps.googleusercontent.com"; string clientSecret = "-xVU6Xwv1o11QrC-uIUawBRY"; string[] scopes = new string[] { "https://www.googleapis.com/auth/contacts" }; // view your basic profile info. try { // Use the current Google .net client library to get the Oauth2 stuff. UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } , scopes , "test" , CancellationToken.None , new FileDataStore("test")).Result; // Translate the Oauth permissions to something the old client libray can read OAuth2Parameters parameters = new OAuth2Parameters(); parameters.AccessToken = credential.Token.AccessToken; parameters.RefreshToken = credential.Token.RefreshToken; RunContactsSample(parameters); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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; //} }
private void GetAuthorization() { // Get the client ID and secret from environment variables for security. var clientId = GetSecretVariable("NINODRIVE_ID"); var clientSecret = GetSecretVariable("NINODRIVE_SECRET"); if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret)) { Console.WriteLine("ERROR Set NINODRIVE_ID and NINODRIVE_SECRET env vars"); Environment.Exit(-1); } // Prepare the OAuth params. oauthParams = new OAuth2Parameters(); oauthParams.ClientId = clientId + ClientId; oauthParams.ClientSecret = clientSecret; oauthParams.RedirectUri = RedirectUri; oauthParams.Scope = Scope; // Since it's a factory it's safe to continue update OAuthParams. requestFactory = new GOAuth2RequestFactory(null, ProgramName, oauthParams); // Try to get the previous token, otherwise request access code. if (!ReadTokenFromFile()) { AskAccessCode(); } }
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 GOAuth2RequestFactory RefreshAuthenticate() { if (string.IsNullOrEmpty(GoogleDataSettings.Instance._RefreshToken) || string.IsNullOrEmpty(GoogleDataSettings.Instance._AccessToken)) { return(null); } if (string.IsNullOrEmpty(GoogleDataSettings.Instance.OAuth2Data.client_id) || string.IsNullOrEmpty(GoogleDataSettings.Instance.OAuth2Data.client_id)) { return(null); } OAuth2Parameters parameters = new OAuth2Parameters() { RefreshToken = GoogleDataSettings.Instance._RefreshToken, AccessToken = GoogleDataSettings.Instance._AccessToken, ClientId = GoogleDataSettings.Instance.OAuth2Data.client_id, ClientSecret = GoogleDataSettings.Instance.OAuth2Data.client_secret, Scope = "https://www.googleapis.com/auth/drive https://spreadsheets.google.com/feeds", AccessType = "offline", TokenType = "refresh" }; return(new GOAuth2RequestFactory("spreadsheet", "MySpreadsheetIntegration-v1", parameters)); }
public static void FinishAuthenticate(GoogleDataSettings settings) { try { OAuth2Parameters parameters = new OAuth2Parameters() { ClientId = settings.OAuth2Data.client_id, ClientSecret = settings.OAuth2Data.client_secret, RedirectUri = REDIRECT_URI, Scope = SCOPE, AccessType = "offline", // IMPORTANT TokenType = TOKEN_TYPE, // IMPORTANT AccessCode = settings._AccessCode }; OAuthUtil.GetAccessToken(parameters); string accessToken = parameters.AccessToken; string refreshToken = parameters.RefreshToken; //Debug.Log("OAuth Access Token: " + accessToken + "\n"); //Debug.Log("OAuth Refresh Token: " + refreshToken + "\n"); settings._RefreshToken = refreshToken; settings._AccessToken = accessToken; } catch (Exception e) { // To display the error message with EditorGUI.Dialogue, we throw it again. throw new Exception(e.Message); } }
public void GetAccessToken() { /* * https://github.com/kimsama/Unity-QuickSheet/blob/50dfaed0397c511ac9da9ee42f64143b3a63e02e/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/Impl/GDataDBRequestFactory.cs#L104-L122 */ Init(); OAuth2Parameters parameters = new OAuth2Parameters(); parameters.ClientId = CLIENT_ID; parameters.ClientSecret = CLIENT_SECRET; parameters.RedirectUri = REDIRECT_URI; parameters.Scope = SCOPE; parameters.AccessType = "offline"; // IMPORTANT parameters.TokenType = TOKEN_TYPE; // IMPORTANT parameters.AccessCode = ACCESS_CODE; OAuthUtil.GetAccessToken(parameters); OAuthUtil.RefreshAccessToken(parameters); ACCESS_TOKEN = parameters.AccessToken; REFRESH_TOKEN = parameters.RefreshToken; EditorUtility.SetDirty(this); }
//Auth for Contacts API public static OAuth2Parameters ContactsAuthtest() { string clientId = "xxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"; string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; string[] scopes = new string[] { "https://www.google.com/m8/feeds/contacts/" }; try { UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }, scopes, "*****@*****.**", CancellationToken.None, new FileDataStore("C:\\Temp\\A\\SharedContactsOauth")).Result; // Translate the Oauth permissions to something the old client libray can read OAuth2Parameters parameters = new OAuth2Parameters(); parameters.AccessToken = credential.Token.AccessToken; parameters.RefreshToken = credential.Token.RefreshToken; return(parameters); } catch (Exception ex33) { Console.WriteLine(ex33.Message); return(null); } }
//private static AuthResult _arAuthResult; public GoogleApiWrapper() { logger.Debug("GoogleApiWrapper ctor"); AuthParams = new OAuth2Parameters(); _thTokenRefreshThread = new Thread(new ThreadStart(_threadAction)); _thTokenRefreshThread.Start(); }
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 ActionResult Index() { var accessGrant = Session["AccessGrant"] as AccessGrant; if (accessGrant != null) { //Until explict GitHub endpoints have API bindings, the following //method can be employed to consume GitHub endpoints var gitHubClient = _gitHubProvider.GetApi(accessGrant.AccessToken); var result = gitHubClient.RestOperations.GetForObject <JsonValue>("https://api.github.com/user/repos"); ViewBag.AccessToken = accessGrant.AccessToken; ViewBag.ResultText = result.ToString(); return(View()); } var parameters = new OAuth2Parameters { RedirectUrl = CallbackUrl, Scope = "repo" }; return(Redirect(_gitHubProvider.OAuthOperations.BuildAuthorizeUrl(GrantType.AuthorizationCode, parameters))); }
/// <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 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 void SaveSate(RegistryKey registryKey, OAuth2Parameters parameters) { registryKey.SetValue("AccessToken", parameters.AccessToken); registryKey.SetValue("AccessCode", parameters.AccessCode); registryKey.SetValue("RefreshToken", parameters.RefreshToken); registryKey.SetValue("TokenExpiry", parameters.TokenExpiry.ToString(System.Globalization.CultureInfo.InvariantCulture)); }
public ActionResult Contact() { ViewBag.Message = "Your contact page."; // Get the tokens from the FileDataStore var token = new FileDataStore("Google.Apis.Auth") .GetAsync <TokenResponse>("user"); //UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync( // new ClientSecrets // { // ClientId = "68942521982-f9h411ncn58sg54s75jctuckes2ibevo.apps.googleusercontent.com", // ClientSecret = "9wyNRGLHjm_Iv_8oUtz0Eojk", // }, // new[] { CalendarService.Scope.Calendar, "https://www.google.com/m8/feeds/" }, // This will ask the client for concent on calendar and contatcs // "user", // CancellationToken.None).Result; //// Create the calendar service. //CalendarService cal_service = new CalendarService(new BaseClientService.Initializer() //{ // HttpClientInitializer = credential, // ApplicationName = "EventManagement", //}); // How do I use the found credential to create a ContactsService???? ContactsService service = new ContactsService("EventManagement"); OAuth2Parameters parameters = new OAuth2Parameters() { ClientId = "68942521982-f9h411ncn58sg54s75jctuckes2ibevo.apps.googleusercontent.com", ClientSecret = "9wyNRGLHjm_Iv_8oUtz0Eojk", RedirectUri = "https://localhost:44300/signin-google", Scope = "https://docs.google.com/feeds/ ", State = "documents", AccessType = "offline" }; parameters.AccessCode = Request.QueryString["code"]; // it gets accesstoken from google Google.GData.Client.OAuthUtil.GetAccessToken(parameters); GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "EventManagement", parameters); service.RequestFactory = requestFactory; //OAuth2Parameters parameters = new OAuth2Parameters //{ // ClientId = "68942521982-f9h411ncn58sg54s75jctuckes2ibevo.apps.googleusercontent.com", // ClientSecret = "9wyNRGLHjm_Iv_8oUtz0Eojk", // // Note: AccessToken is valid only for 60 minutes // // AccessToken = token.Result.AccessToken, // // RefreshToken = token.Result.RefreshToken //}; RequestSettings settings = new RequestSettings("EventManagement", parameters); ContactsRequest cr = new ContactsRequest(settings); GContactData gdata = new GContactData(); gdata.PrintDateMinQueryResults(cr); return(View()); }
public SpreadSheetManager(OAuth2Parameters parameters) { GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters); service = new SpreadsheetsService("MySpreadsheetIntegration-v1"); service.RequestFactory = requestFactory; }
public static AppsService CreateAppsService(string domain, OAuth2Parameters parameters) { GOAuth2RequestFactory factory = new GOAuth2RequestFactory("apps", FrameworkConfiguration.Current.WebApplication.Integration.Google.ApplicationName, parameters); AppsService service = new AppsService(domain, parameters.AccessToken); service.SetRequestFactory(factory); return(service); }
public void LoginToGoogle(string username) { UserName = username; //OAuth2 for all services List <String> scopes = new List <string>(); //Contacts-Scope scopes.Add("https://www.google.com/m8/feeds"); ////Notes-Scope //scopes.Add("https://docs.google.com/feeds/"); ////scopes.Add("https://docs.googleusercontent.com/"); ////scopes.Add("https://spreadsheets.google.com/feeds/"); ////Calendar-Scope ////scopes.Add("https://www.googleapis.com/auth/calendar"); //scopes.Add(CalendarService.Scope.Calendar); //take user credentials UserCredential credential; //load client secret from ressources byte[] jsonSecrets = Properties.Resources.client_secrets; using (var stream = new MemoryStream(jsonSecrets)) { var fDs = new FileDataStore(Folder + "\\Authen\\" + UserName, true); var clientSecrets = GoogleClientSecrets.Load(stream); credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync( clientSecrets.Secrets, scopes.ToArray(), username, CancellationToken.None, fDs). Result; var initializer = new Google.Apis.Services.BaseClientService.Initializer(); initializer.HttpClientInitializer = credential; OAuth2Parameters parameters = new OAuth2Parameters { ClientId = clientSecrets.Secrets.ClientId, ClientSecret = clientSecrets.Secrets.ClientSecret, // Note: AccessToken is valid only for 60 minutes AccessToken = credential.Token.AccessToken, RefreshToken = credential.Token.RefreshToken }; RequestSettings settings = new RequestSettings("Google Contact Sync - Seta International", parameters); ContactsRequest = new ContactsRequest(settings); } }