我目前有一个后端解决方案,使用Azure Mobile Apps。我已经启用了Facebook、Twitter、Google和Microsoft登录。我正在尝试添加自定义登录流程。我设置了一个Auth0帐户和应用程序,当我在应用程序中使用auth0锁小部件发出请求时,我可以从auth0获取令牌和配置文件。
我遵循了这个指南:https://shellmonger.com/2016/04/08/30-days-of-zumo-v2-azure-mobile-apps-day-5-custom-authentication/并到达了“服务器上的自定义JWT验证”阶段,但这就是我卡住的地方……我的后端是使用C#而不是node.js开发的,所以我该如何实现此教程的等效操作,并验证JWT令牌,随后使用azureClient.login/azureClient.table从我的前端应用程序访问表控制器?
编辑:好吧,正如您将在与@AdrianHall的评论线程下看到的那样,我成功地从我的cordova应用程序内部生成了令牌,但我的绊脚石是使服务接受它而无需交换令牌。根据发布的指南,这是可能的。
这是我的客户端代码,目前调用auth0并进行一些客户端设置,以获取userID并生成包含新令牌的“currentUser”对象。
我遵循了这个指南:https://shellmonger.com/2016/04/08/30-days-of-zumo-v2-azure-mobile-apps-day-5-custom-authentication/并到达了“服务器上的自定义JWT验证”阶段,但这就是我卡住的地方……我的后端是使用C#而不是node.js开发的,所以我该如何实现此教程的等效操作,并验证JWT令牌,随后使用azureClient.login/azureClient.table从我的前端应用程序访问表控制器?
编辑:好吧,正如您将在与@AdrianHall的评论线程下看到的那样,我成功地从我的cordova应用程序内部生成了令牌,但我的绊脚石是使服务接受它而无需交换令牌。根据发布的指南,这是可能的。
这是我的客户端代码,目前调用auth0并进行一些客户端设置,以获取userID并生成包含新令牌的“currentUser”对象。
auth0.lock.show(auth0.options, function(err, profile, token) {
if (err) {
console.error('Error authenticating with Auth0: ', err);
alert(err);
} else {
debugger;
var userID;
if (profile.user_id.indexOf("auth0") > -1) {
userID = profile.user_id.replace("auth0|", "");
} else if (profile.user_id.indexOf("facebook") > -1) {
userID = profile.user_id.replace("facebook|", "");
} else if (profile.user_id.indexOf("twitter") > -1) {
userID = profile.user_id.replace("twitter|", "");
} else if (profile.user_id.indexOf("microsoft") > -1) {
userID = profile.user_id.replace("microsoft|", "");
} else if (profile.user_id.indexOf("google-oauth2") > -1) {
userID = profile.user_id.replace("google-oauth2|", "");
}
window.azureClient.currentUser = {
userId: userID,
profile: profile,
mobileServiceAuthenticationToken: token
};
//A client session has now been created which contains attributes relevant to the currently logged in user.
console.log("window.azureClient.currentUser", window.azureClient.currentUser);
window.localStorage.setItem("currentUser", JSON.stringify(window.azureClient.currentUser));
//Call the get profile function which will call our API to get the user's activities and bio etc.
getProfile();
}
后端代码 MobileAppSettings字典
settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
if (string.IsNullOrEmpty(settings.HostName))
{
//This middleware is intended to be used locally for debugging.By default, HostName will
//only have a value when running in an App Service application.
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
SigningKey = ConfigurationManager.AppSettings[""],
ValidAudiences = new[] { ConfigurationManager.AppSettings[""] },
ValidIssuers = new[] { ConfigurationManager.AppSettings["https://domain.eu.auth0.com/"] },
TokenHandler = config.GetAppServiceTokenHandler()
});
}