public object RefreshOauth() { var CLIENT_ID = "570313910467-h8raudku9n9n65118tqndopih9breo53.apps.googleusercontent.com"; var CLIENT_SECRET = "T8vlM82EEb82IAtDSaey-Oet"; ClientSecrets secrets = new ClientSecrets { ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET }; TokenResponse token = new TokenResponse { AccessToken = "sfd", RefreshToken = "1/RcTEm-ZKEtBZzS2jOVLONQcmhtEpRZ7r2zny2HjWtMY" }; IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = secrets, Scopes = new string[] { DriveService.Scope.Drive } }); UserCredential credential = new UserCredential(flow, "me", token); bool success = credential.RefreshTokenAsync(CancellationToken.None).Result; token = credential.Token; string access = token.AccessToken; var dbCtx = new CompassDBEntities(); var oauthVal = new DriveOauth(); oauthVal.Id = 1; var DriveAuth = dbCtx.DriveOauths.Find(oauthVal.Id); DriveAuth.AccessToken = token.AccessToken; DriveAuth.ExpireTime = token.ExpiresInSeconds.ToString(); DriveAuth.IssueTime = token.Issued.ToString(); dbCtx.SaveChanges(); return token; }
public CompassUser NewUser() { var userId = HttpContext.Current.User.Identity.GetUserId(); var newuser = new CompassUser(); newuser.LinkedId = userId; newuser.Name = "name_"; // insert using (var db = new CompassDBEntities()) { var users = db.Set<CompassUser>(); users.Add(newuser); db.SaveChanges(); } return newuser; }