c# - ASP.NET Core Web API Facebook JWT Authentication -


i trying implement facebook based authentication in asp.net core web api. searched lot , read of blog related authentication in asp.net core using jwt did not found of article using facebook authenticate , generate jwt. of article using asp.net core mvc login using facebook.i tried adding in web api after submitting username , password facebook instead of redirecting externallogincallback gives error 404.

enter image description here

  [httppost]     [allowanonymous]     public iactionresult externallogin(string provider, string returnurl = null)     {         // request redirect external login provider.         var redirecturl = url.action(nameof(externallogincallback), "account", new { returnurl });         var properties = _signinmanager.configureexternalauthenticationproperties(provider, redirecturl);         return challenge(properties, provider);     }      [httpget]     [allowanonymous]     public async task<iactionresult> externallogincallback(string returnurl = null, string remoteerror = null)     {         if (remoteerror != null)         {             errormessage = $"error external provider: {remoteerror}";             return badrequest();         }         var info = await _signinmanager.getexternallogininfoasync();         if (info == null)         {             return badrequest();         }         var claims = info.principal.claims;         var key = new symmetricsecuritykey(encoding.utf8.getbytes("tokenkeys"));         var creds = new signingcredentials(key, securityalgorithms.hmacsha256);          var token = new jwtsecuritytoken("myapi",           "myapi",           claims,           expires: datetime.now.adddays(30),           signingcredentials: creds);          return ok(new { token = new jwtsecuritytokenhandler().writetoken(token) });     } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -