public void StoreCredentials(UserCredentialModel credential)
 {
     credentialsRepository.StoreCredentials(new UserCredential()
     {
         AccessToken = credential.AccessToken ,
         RefreshToken = credential.RefreshToken,
         UserId = credential.UserId
     });
 }
Exemplo n.º 2
0
        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCookieAuthentication(new CookieAuthenticationOptions
               {
               AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
               LoginPath = new PathString("/Account/Login")
               });

               app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

               //app.UseGoogleAuthentication();
               var glassProvider = new GlassAuthenticationProvider
               {
               OnAuthenticated = context =>
               {
                   var accessToken = context.AccessToken;
                   var refreshToken = context.RefreshToken;
                   var userId = context.Id;
                   var credentialService = DependencyResolver.Current.GetService<ICredentialService>();
                   var userCredential = new UserCredentialModel()
                   {
                       UserId = userId,
                       AccessToken = accessToken,
                       RefreshToken = refreshToken
                   };
                   credentialService.StoreCredentials(userCredential);
                   return Task.FromResult<object>(null);
               }
               };
               var config = DependencyResolver.Current.GetService<IConfiguration>();
               app.UseGlassAuthentication(new GlassAuthenticationOptions
               {
               //Remove Hardcode Key & Revoke Id Below
               ClientId = config.ClientId,
               ClientSecret = config.ClientSecret,
               Provider = glassProvider,
               Scope = new List<string>
            {
                "https://www.googleapis.com/auth/glass.timeline",
                "https://www.googleapis.com/auth/glass.location",
                "https://www.googleapis.com/auth/userinfo.profile",
                "https://www.googleapis.com/auth/userinfo.email"
            }
               });
        }