What is the correct way to legitimize a particular user through Identity with Soap web service?

Asked

Viewed 61 times

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?

1 answer

1


Identity is used in MVC, in Webservice this works different, each request in WS is a new request, different from when you are running some site on IIS.

One-night stand here you will understand how to authenticate on a WS.

ReportingService service = new ReportingService();
service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.