首页 > 解决方案 > 更改 WSO2 IS 5.9.0 中用户名的正则表达式限制后,Token Introspect API 不起作用?

问题描述

我正在使用 WSO2 身份服务器并使用电子邮件作为以下文档中的用户名 - https://is.docs.wso2.com/en/5.9.0/learn/using-email-address-as-the-username/

然后在执行注册时,即使用电子邮件超过 30 个字符的 SCIM2 API 创建用户时,我收到以下错误-

{
    "schemas": [
        "urn:ietf:params:scim:api:messages:2.0:Error"
    ],
    "scimType": "invalidValue",
    "detail": "31301 - Username test1233.admin@motioneducation.com is not valid. User name must be a non null string with following format, ^[\\S]{3,30}$",
    "status": "400"
}

然后为了解决这个问题,我在用户存储的 deployment.toml 文件中添加了这个正则表达式 -

[user_store]
username_java_script_regex = '^[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$'
username_java_regex='^[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'

此更改修复了我的注册问题,但通过使用 wso2 /oauth2/token API 执行登录生成的令牌在 /oauth2/introspect API 中给出 401 未授权?

请帮忙........?

标签: wso2wso2iswso2carbon

解决方案


由于您已启用电子邮件作为用户名,因此您还需要在授权标头中使用电子邮件用户名。下面给出了一个示例 curl 命令。

curl --location --request POST 'https://{host_name}:{port}/oauth2/introspect' --header '内容类型:application/x-www-form-urlencoded' --header '授权:基本{base64encode(emailusername:password)}' --data-urlencode 'token={access_token}'

样品请求

curl --location --request POST ' https://localhost:9443/oauth2/introspect ' --header '内容类型:application/x-www-form-urlencoded' --header '授权:基本 YWRtaW5Ad3NvMi5jb206YWRtaW4=' - -data-urlencode 'token=47f65812-c5fb-3f90-b5c0-3bbc3603578f'

仅当您发送无效凭据时才会出现 401 未经授权的错误。所以请检查您是否在授权标头中发送了有效的电子邮件用户名和有效密码


推荐阅读