AFNetworking: How/when to prompt for username and password for BASIC Auth?

谁都会走 提交于 2019-12-08 09:01:50

问题


I'm looking for a best-practice about prompting the user for credentials. I have to code for the possibility that after the user logs in from the phone, he/she could login from another device or webpage and change the password. Since I'm doing BASIC auth, that token will now be incorrect and I need to handle it appropriately.

I've started a new project with AFNetworking. I have subclassed AFHTTPClient and I've overridden the HTTPRequestOperationWithRequest message to set a authentication challenge block on it after I make the call to super. In that block I should create a new NSURLCredential object and send it back to the sender. I get it so far.

What I don't get is how I'm supposed to prompt the user. Ideally I'd like to push a login screen on my nav controller with a login button. Clicking the login button would create the NSURLCredential and send it back to the sender.

  • Should I somehow block inside the challenge block? That doesn't seem right.
  • Should I save the NSURLAuthenticationChallenge object to a global? Eww.
  • Should I push the login page from my subclassed AFHTTPClient? Sounds like I'm violating separation of concerns.
  • Should I call my AppDelegate to prompt the user and pass the NSURLAuthenticationChallenge object to it? Sounds better, but still unsure.

来源:https://stackoverflow.com/questions/15846695/afnetworking-how-when-to-prompt-for-username-and-password-for-basic-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!