我想从Okta获取其他信息,因为使用this.props.auth.getUser()
我将仅收到有关用户的电子邮件,姓名和姓氏。但是Okta上有很多数据,例如州,城市,街道地址,邮政编码等。
我正在使用ReactJS和Node express创建一个Web应用,并且登录由Okta(https://developer.okta.com/)管理,然后我想将有关用户的Okta信息存储在数据库中。
async checkAuthentication() {
const authenticated = await this.props.auth.isAuthenticated();
if (authenticated !== this.state.authenticated) {
const user = await this.props.auth.getUser();
console.log(this.props.auth);
this.setState({
authenticated,
user
});
this.getUsers();
}
}
async getUsers() {
let params = "";
let url = "";
if (this.state.user != null) {
params += "EMAIL=" + this.state.user.email;
}
url = params == null ? "/user" : "/user?";
url += params;
this.state.users = await this.fetch('get', url);
if (this.state.users && Object.keys(this.state.users).length == 0) {
this.saveUser();
}
}
async saveUser() {
var user = {
EMAIL: this.state.user.email,
NAME: this.state.user.given_name,
SURNAME: this.state.user.family_name,
//ORGANIZATION: "this.state.user.organization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",
};
await this.fetch('post', '/user', user);
}
在这里,我想从Okta保存其他数据。
//ORGANIZATION: "this.state.user.organization",
//PHONE = "this.state.user.primaryPhone",
//STATE = "this.state.user.state",
//STREET_ADDRESS = "this.state.user.streetAddress",
//ZIP_CODE = "this.state.user.zipCode",
答案 0 :(得分:0)
您需要指定要作为范围的对象。 Okta的默认范围为以下offline_access,电话,地址,电子邮件,个人资料,openid。在配置中,您可以使用以下文档https://developer.okta.com/authentication-guide/implementing-authentication/
答案 1 :(得分:0)
auth.getUser()返回授权服务器上/ userinfo端点下可用的详细信息,通过该服务器可以对用户进行身份验证和授权,如此处所述。
如果您还想在此/ endpoint上发布其他详细信息,请执行以下操作: