我已按照以下文档中的步骤进行操作http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-get-started-custom-authentication/
并构建了我的.NET后端 - 我已经能够使用&#34运行移动服务的新CustomRegistration和CustomLogin功能;试试这个"按钮上
localhost:<portNumber>/help/Api/POST-api-CustomLogin
和。./CustomRegistration
各自的api页面。我已经将这些渠道发布到我的天蓝色移动服务中。
然后我尝试使用我在Android Studio中构建的Android应用程序连接到该服务。我对Android非常陌生,因此我无法使用我的应用 我的移动服务提供的CustomLogin。 Android APP的代码下面
在java / com.example.howzit文件夹中:
LoginResult.java
package com.example.howzit;
import com.google.gson.annotations.SerializedName;
public class LoginResult {
public String AuthenticationToken;
//
// Summary:
// Gets or sets the Microsoft.WindowsAzure.Mobile.Service.Security.LoginResultUser
// logged in.
public LoginResultUser User;
}
LoginResultUser.java
package com.example.howzit;
import com.google.gson.annotations.SerializedName;
public class LoginResultUser {
public String UserId ;
}
LoginRequest.java
package com.example.howzit;
public class LoginRequest
{
public String username ;
public String password ;
}
在TodoActivity课程中我有这个:
mClient = new MobileServiceClient(
"https://mysite.azure-mobile.net/",
"APIKEY",
this).withFilter(new ProgressFilter())
.withFilter(new RefreshTokenCacheFilter());
LoginRequest loginUser = new LoginRequest();
loginUser.username = "theUserName";
loginUser.password = "thePassword";
mClient.invokeApi("CustomLogin",loginUser,LoginResult.class, new ApiOperationCallback<LoginResult>() {
@Override
public void onCompleted(LoginResult result,Exception error, ServiceFilterResponse response ){
if (error != null) {
createAndShowDialog(error, "Error");
}
else {
createAndShowDialog(result.User.UserId, "User");
}
}
});
我已经调试了它,它基本上命中了invokeApi调用并继续加载其余的 应用程序永远不会触及onCompleted例程...在Android Studio中我可以访问LogCat,但没有任何内容可以告诉我错误。我真的无法深究这一点。我已经成功实施了Google登录提供程序以及Window Azure 提供商,但我无法使用自己的自定义登录。任何帮助将不胜感激。
更多信息:我在VS2013上设置了远程调试,如果我删除了身份验证和调试,在使用Android应用程序时会遇到断点,但是在使用身份验证时,Controller中的CustomLogin Post永远不会被命中。
答案 0 :(得分:1)
我遇到了同样的问题。亚当的回答非常有帮助! 但是,您需要拨打帐户/ CustomLogin / ,而不是调用 / api / Account / CustomLogin 。
mClient.invokeApi("Account/CustomLogin/",...
然后,代码应该在你的后端调用。情况可能仍然是这样,您不会从后端获得返回值。要解决这个问题,这个问题可能有所帮助:
答案 1 :(得分:0)
即使不确定答案是否正确,只需将此答案更清楚。
尝试放
[AuthorizeLevel(AuthorizationLevel.Anonymous)]
[Route("api/Account/CustomLogin")]
[HttpPost]
作为自定义api控制器方法上方的属性,然后尝试调用/ api / Account / CustomLogin