简体   繁体   English

有什么办法可以在auth0规则中获取用户的语言?

[英]Is there any way to get user's language in auth0 rules?

I want to create a rule in auth0 that will add user's language to user's id token. 我想在auth0中创建一个规则,该规则会将用户的语言添加到用户的ID令牌中。 So is there any way to achieve that? 那么有什么方法可以实现? I can get country code and some other info from geoip but I can't get language anywhere 我可以从geoip获取国家代码和其他一些信息,但是我在任何地方都无法获得语言

If you don't already have the langauge you could collect the user's language during the signup process by using the additionalsignupfields option in Lock to show a drop-down of languages. 如果你还没有的的langauge,你可以在使用注册过程中收集用户的语言additionalsignupfields在锁定选项来显示的语言下拉。 The user would then select an option during sign up and the selected value can be persisted in user_metadata . 然后,用户将在注册期间选择一个选项,并且所选值可以user_metadatauser_metadata

Alternatively, you can customize your login page using JavaScript to detect the user's browser language, then auto-populate an additionalsignupfield in Lock with the value. 或者,您可以使用JavaScript自定义您的登录页面以检测用户的浏览器语言,然后使用该值自动填充Lock中的additionalsignupfield signupfield。 We could even make this a hidden field if necessary. 如有必要,我们甚至可以将其设为隐藏字段。

Once stored in user_metadata we can then add that to the id_token something like: 一旦存储在user_metadata我们就可以将其添加到id_token ,如下所示:

function(user, context, callback) {

  // copy user metadata value in id token
  context.idToken['http://examplesite/user_lang'] = user.user_metadata.user_lang;

  callback(null, user, context);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM