首页 文章

如何获得isAuthenticated在客户端mvc app中工作,在跨平台身份验证和autherization(web api)

提问于
浏览
0

我正在使用mvc应用程序和带有asp.net身份的web api 2.我的客户端mvc应用程序使用令牌,它在登录提交按钮上给出api调用然后web api服务返回一个令牌和用户声明(即用户名)我的问题是以下:

  • 如何在我的mvc应用程序中使用IsAuthenticated属性,因为它始终为false .

  • 如何根据我的用途记住我的功能 .

  • 我的api是否有必要返回userclaim-username和accessstoken以及其他数据,我可以按照用户的说法收到电子邮件和电话 .

Update:

public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {

            return View(model);
        }
        var responseDictionary = GetResponseAsDictionary(model.usename, model.password);
       return View(model);
    }

我从web api获得这个响应字典

现在如何在服务中使用此令牌设置 IsAuthenticated ?我知道如何在表单身份验证中执行此操作,但我不知道如何使用AccessTokens执行此操作,并且我还希望在tempData或session中的用户会话中保留此标记 .

1 回答

  • -1
    it was easy to do , i can use 
    `
    formsAuthentication.SetAuthCookie
    
    ` on Client app and i had to redirect the page after setting this cookie
    
    1: Get the Authtoken from web api 
    2: if it returns Access_token ,then you can set authcookie
    3: finnaly you can use IsAuthenticated property on client App 
    
    4: i would ask another question for how to do a remember me feature 
    ,as i dont know how to store token and is 
    it safe to store as it is without further encripting it.
    

相关问题