Пример #1
0
        public CompassUser GetUser()
        {
            var db = new CompassDBEntities();
            var userId = HttpContext.Current.User.Identity.GetUserId();
            var compassuser = _repository.Users
                            .Where(u => u.LinkedId == userId)
                            .FirstOrDefault();

            if (compassuser == null)
            {
                return null;
            }
            else
            {
                return compassuser;
            }

        }
Пример #2
0
        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;
        }
Пример #3
0
        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;
        }