lundi 28 novembre 2016

Asp.NET Web Api GetExternalLoginInfoAsync() Allways returns null

I am not able to use the External Login (google and facebook) by calling api. My info variable which returns external credentials is always null. But when I call GET /api/Account/UserInfo, I can actually see user's Email and that he is not registered in my application yet.

 public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Username, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }

I have seen similar problems on the web, but it is not clear how to solve this issue.




Aucun commentaire:

Enregistrer un commentaire