Travailler dans ASP.NET avec C# pour les applications Windows Forms, je cherche à fournir la fonctionnalité de connexion via Google a/c par Oauth2
. Est-ce que n'importe quel corps peut m'aider avec un échantillon ou des liens pour sortir du problème?Google Oauth2 Connexion
0
A
Répondre
1
Vous trouverez un exemple ici: / - google-api-dotnet-client - Google APIs Client Library for .NET - Google Project Hosting
1
3 type login with OAuth2.
private async Task SignInAsync(User user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() {IsPersistent = isPersistent }, identity);
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await _userManager.FindAsync(model.UserName, model.Password);
//Update : here we need to optimize code , because we have many roles and logins.
//According to role we need to open Dashboards.
if (user != null)
{
IList<string> roles = await _userManager.GetRolesAsync(user.Id);
if (roles.Count != 0)
{
this.SessionState.ThemeName = user.ThemeName;
this.SessionState.UserId = user.Id;
this.SessionState.CustomerId = user.CustomerId.ToString();
this.SessionState.UserRole = roles.FirstOrDefault().ToString();
if (SessionState.UserRole == UserRoleNames.ClinicAdmin || SessionState.UserRole == UserRoleNames.ClinicStaff || SessionState.UserRole == UserRoleNames.Patient)
{
this.SessionState.SiteId = user.SiteId.ToString();
}
else
{
this.SessionState.SiteId = null;
}
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
else
{
ModelState.AddModelError("", "Your account is not activate ,Please contact administrator");
}
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
return this.AjaxableView(model);
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Manage");
}
if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
var info = await AuthenticationManager.GetExternalLoginInfoAsync();
if (info == null)
{
return this.AjaxableView("ExternalLoginFailure");
}
var user = new User() { UserName = model.UserName };
var result = await _userManager.CreateAsync(user);
if (result.Succeeded)
{
result = await _userManager.AddLoginAsync(user.Id, info.Login);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl);
}
}
AddErrors(result);
}
ViewBag.ReturnUrl = returnUrl;
return this.AjaxableView(model);
}
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
var user = await _userManager.FindAsync(loginInfo.Login);
if (user != null)
{
await SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl);
}
else
{
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
return this.AjaxableView("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { UserName = loginInfo.DefaultUserName });
}
}
Questions connexes
- 1. Python Oauth2 - connexion avec Google
- 2. Laravel Oauth2 Connexion
- 3. Google OAuth2 supprimer l'invite
- 4. CodeNameOne Google Plus OAuth2
- 5. DotNetOpenAuth Google OAuth2
- 6. OAuth2 Connexion sur Android et iOS
- 7. La connexion Oauth2 expire sur AWS
- 8. concevoir + erreurs d'appel omniauth-google-oauth2
- 9. Google Drive SDK alternateLink avec OAuth2
- 10. moteur google app moteur oauth2
- 11. API Google Contacts OAuth2 d'émission
- 12. Google oauth2 - Appel à Token
- 13. Google OAuth2 API Refresh Tokens
- 14. Mettre en œuvre google oAuth2
- 15. obtenir l'utilisateur par l'accès google oauth2 token
- 16. Google oauth2 get accessToken en utilisant javascript
- 17. OAuth2 Authentification pour "Google Service" renvoie "invalid_request"
- 18. Google OAuth2 Inscription à Concevoir avec AngularJS
- 19. Authentifier mon application web avec google oauth2
- 20. Client API Google Actualiser le jeton OAuth2
- 21. Problème avec l'authentification OAuth2 avec google spreadsheet
- 22. avec petit bijou omniauth Devise-google-oauth2
- 23. Google+ OAuth2 sur iPhone comment se déconnecter
- 24. Node.js OAuth2: Les activités à Google+
- 25. API Google Sites: OAuth2 pour Java
- 26. comment utiliser Google OAuth2 en utilisant ServiceAccount dans .net?
- 27. Google OAuth2 Authentification Mechaniszm requiert une connexion utilisateur à chaque fois
- 28. Flux Google OAuth2 dans l'application Web côté serveur en Java
- 29. Comment obtenir le courrier électronique de Google Python SDK oauth2?
- 30. Serveur JHipster OAuth2 - page de connexion pour/oauth/autoriser