2
Initially I tried to add snippets that are related to Identity and I used the Find method with password and login, but I was not successful.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Testeando_MVC5.ViewModels;
using Testeando_MVC5.Models;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Text;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using Microsoft.AspNet.Identity.EntityFramework;
using Testeando_MVC5.Identity;
using System.Data.Entity;
using System.Data.Entity.Core;
using System.Net;
using Microsoft.Owin.Host.SystemWeb;
using System.Security.Cryptography;
namespace Testeando_MVC5
{
/// <summary>
/// Summary description for Teste1
/// </summary>
[WebService(Namespace = "https://localhost:44300/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Teste1 : System.Web.Services.WebService
{
private ApplicationDbContext db = new ApplicationDbContext();
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
//sem sucesso
// return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
//return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
return _userManager ;
}
private set
{
_userManager = value;
}
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string[] TesteAuth(string login, string senha)
{
//reza a lenda que esses dados podem sofrer alteração pois isso passei assim
byte[] loginBytes = Convert.FromBase64String(login);
byte[] senhaBytes = Convert.FromBase64String(senha);
string[] retorno = new string[2];
retorno[0] = Encoding.UTF8.GetString(loginBytes);
retorno[1] = Encoding.UTF8.GetString(senhaBytes);
string email = Encoding.UTF8.GetString(loginBytes);
string senhaR = Encoding.UTF8.GetString(senhaBytes);
// metodo que busca user
var user = _userManager.Find(email, senhaR);
//somente para teste
//var query = from c in db.Users
// where c.UserName.Contains(email)
// select new { c.UserName, c.PasswordHash, c.ConfigContas };
//var results = query.FirstOrDefault();
//if (results != null)
//{
// if (senhaR.Equals(results.PasswordHash))
// {
// retorno[3] = "Usuario Existente";
// }
//}
return retorno;
}
}
}
How would this stretch on a web service:
return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
There is something specific about Identity for web service?