locked
how to create a token and then after authorize person access that actionresult index method in asp.net mvc? RRS feed

  • Question

  • User1421057020 posted

    now when I click on the send button of postman then direct access the index method that is issue I want to generate a token and then after authorize person access that method

    staticvariable.cs

        public static class staticvariable
        {
            public static HttpClient webapiclient = new HttpClient();
    
            static staticvariable()
            {
                webapiclient.BaseAddress = new Uri("http://localhost:5718/api/");
                webapiclient.DefaultRequestHeaders.Clear();
                webapiclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            }
        }

    studController.cs

        public class studController : Controller
        {
            // GET: Home
            public JsonResult Index()
            {
                IEnumerable<student> studlist;
                HttpResponseMessage response = staticvariable.webapiclient.GetAsync("stud").Result;
                studlist = response.Content.ReadAsAsync<IEnumerable<student>>().Result;
                return Json(studlist,JsonRequestBehavior.AllowGet);
            }
        }

    what i want to the

    when click on the send button of the postman then after generate the token means authoriz person can access that index method

    Saturday, June 13, 2020 5:21 PM

All replies

  • User-474980206 posted

    you will need to pick an authentication scheme and implement. Then just add the authorize attribute to the controller. 

    Saturday, June 13, 2020 9:03 PM
  • User1421057020 posted

    hi burce

    can you give good referance or link for authentication scheme implement?

    Sunday, June 14, 2020 5:54 AM
  • User-474980206 posted

    Which are Identity are planning on using, basic, digest, cookie, certificate, or bearer tokens? If bearer tokens, which oauth server are you using?

    Sunday, June 14, 2020 5:06 PM
  • User1421057020 posted

    Hi bruce

    I am planning OAuth 2.0 APIs with Bearer Token

    please help more how to get the token?

    still I does not get the Token in Postman? 

    Monday, June 15, 2020 4:55 PM
  • User475983607 posted

    The following link illustrates how to build an OAuth token server that you host.

    https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server

    If you are trying to access a remote token server then you must read the support documentation for the service. 

    Monday, June 15, 2020 5:17 PM