OIDC通过token获取用户信息失败

使用相同的access_token请求https://bi-test.authing.cn/oidc/me和https://bi-test.authing.cn/api/v3/get-profile,前者正常返回,后者用户池不存在,为什么?
而且获取code是scope=openid username,并没有返回username


curl --location --request GET ‘https://bi-test.authing.cn/api/v3/get-profile’ \

–header ‘access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlN2N0pXOUxxVUIwd3M3a3B0cjRJR1BGMlNtckM4cC1rZERYU2NuR2ZQSm8ifQ.eyJzdWIiOiI2NTRjOTExNzg5ZWE0NjQ0OTgwOWNmNTkiLCJhdWQiOiI2NTRjOGQ3NTNhMjlmMTlhZGY5NzMyMDYiLCJzY29wZSI6Im9wZW5pZCBlbWFpbCBwaG9uZSBvZmZsaW5lX2FjY2VzcyBwcm9maWxlIiwiaWF0IjoxNjk5NTI1NDk1LCJleHAiOjE3MDA3MzUwOTUsImp0aSI6IlFVazZkc1FOQ1FqT1MzWlZ3aXN5WnI0TXFLclEtZG9nckg5clp1TFdxSGwiLCJpc3MiOiJodHRwczovL2JpLXRlc3QuYXV0aGluZy5jbi9vaWRjIn0.ZC57VfevTnXSZIPAmKcr58XSzjvyszNRbV194Wu_4L4eGNYlL0UzLFISuPCodQdzI-h4xjtU10FXWehO4y_Jo56eueZUNSM-Tg7YpVKkFoPlXA7TJbJ1MmrDzo6FFENgEJDH7aKQWAjRHwLj62BatXTSh4A_fndFsbQqecwTZhF1fYyQsoSmvVrBI_6Is9uNaC0iNSlNHDI2NXBtvSI6NOKY-wzLPyT_D883jBCiY3ckz6YGKxeuFWXTIO3t7TLtbSj-_loRyJWQ_6iiBm9Rr5noHMHEFWZ82iBTc3KXAB5jIGt00_KUZMgyxhMQl-CKuw0g6jzC_p6dJX7nGRNgag’


curl --location --request GET ‘https://bi-test.authing.cn/oidc/me?access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlN2N0pXOUxxVUIwd3M3a3B0cjRJR1BGMlNtckM4cC1rZERYU2NuR2ZQSm8ifQ.eyJzdWIiOiI2NTRjOTExNzg5ZWE0NjQ0OTgwOWNmNTkiLCJhdWQiOiI2NTRjOGQ3NTNhMjlmMTlhZGY5NzMyMDYiLCJzY29wZSI6Im9wZW5pZCBlbWFpbCBwaG9uZSBvZmZsaW5lX2FjY2VzcyBwcm9maWxlIiwiaWF0IjoxNjk5NTI1NDk1LCJleHAiOjE3MDA3MzUwOTUsImp0aSI6IlFVazZkc1FOQ1FqT1MzWlZ3aXN5WnI0TXFLclEtZG9nckg5clp1TFdxSGwiLCJpc3MiOiJodHRwczovL2JpLXRlc3QuYXV0aGluZy5jbi9vaWRjIn0.ZC57VfevTnXSZIPAmKcr58XSzjvyszNRbV194Wu_4L4eGNYlL0UzLFISuPCodQdzI-h4xjtU10FXWehO4y_Jo56eueZUNSM-Tg7YpVKkFoPlXA7TJbJ1MmrDzo6FFENgEJDH7aKQWAjRHwLj62BatXTSh4A_fndFsbQqecwTZhF1fYyQsoSmvVrBI_6Is9uNaC0iNSlNHDI2NXBtvSI6NOKY-wzLPyT_D883jBCiY3ckz6YGKxeuFWXTIO3t7TLtbSj-_loRyJWQ_6iiBm9Rr5noHMHEFWZ82iBTc3KXAB5jIGt00_KUZMgyxhMQl-CKuw0g6jzC_p6dJX7nGRNgag

  1. 请求 /api/v3/get-profile 的时候需要在请求头设置应用 id:
x-authing-app-id: "应用的 id"

我们会优化一下接口,如果使用二级域名调用接口的时候,不需要再在请求头里面传。

  1. scope 试试 openid profile
1赞

谢谢回复,但遇到了新的问题,加上id后返回如下,用openid profile不会返回用户名吧,对接的系统需要获取到用户名实现登录(没同步id)

{ "statusCode": 401, "apiCode": 2020, "message": "尚未登录,无访问权限", "requestId": "735960f7-cbbc-475f-85b2-599c89927572" }

请求如下
curl --location --request GET 'https://bi-test.authing.cn/api/v3/get-profile' \ --header 'access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlN2N0pXOUxxVUIwd3M3a3B0cjRJR1BGMlNtckM4cC1rZERYU2NuR2ZQSm8ifQ.eyJzdWIiOiI2NTRjOTExNzg5ZWE0NjQ0OTgwOWNmNTkiLCJhdWQiOiI2NTRjOGQ3NTNhMjlmMTlhZGY5NzMyMDYiLCJzY29wZSI6Im9wZW5pZCBlbWFpbCBwaG9uZSBvZmZsaW5lX2FjY2VzcyBwcm9maWxlIiwiaWF0IjoxNjk5NTI1NDk1LCJleHAiOjE3MDA3MzUwOTUsImp0aSI6IlFVazZkc1FOQ1FqT1MzWlZ3aXN5WnI0TXFLclEtZG9nckg5clp1TFdxSGwiLCJpc3MiOiJodHRwczovL2JpLXRlc3QuYXV0aGluZy5jbi9vaWRjIn0.ZC57VfevTnXSZIPAmKcr58XSzjvyszNRbV194Wu_4L4eGNYlL0UzLFISuPCodQdzI-h4xjtU10FXWehO4y_Jo56eueZUNSM-Tg7YpVKkFoPlXA7TJbJ1MmrDzo6FFENgEJDH7aKQWAjRHwLj62BatXTSh4A_fndFsbQqecwTZhF1fYyQsoSmvVrBI_6Is9uNaC0iNSlNHDI2NXBtvSI6NOKY-wzLPyT_D883jBCiY3ckz6YGKxeuFWXTIO3t7TLtbSj-_loRyJWQ_6iiBm9Rr5noHMHEFWZ82iBTc3KXAB5jIGt00_KUZMgyxhMQl-CKuw0g6jzC_p6dJX7nGRNgag' \ --header 'x-authing-app-id: 654c8d753a29f19adf973206' \ --header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \ --header 'Accept: */*' \ --header 'Host: bi-test.authing.cn' \ --header 'Connection: keep-alive'

看你发的这个 access token 并没有带 username 的 scope

/oidc/auth?_authing_lang=zh-CN&client_id=61XXXXXXX14b3&nonce=m8SNdDtN92&redirect_uri=https%3A%2F%2F.com&response_type=code&scope=openid%20username 给你一个发起授权的参考,你可以换取后再试试 /oidc/me

1赞

请求头需要使用 authorization 哈,不是 access_token

谢谢!这里搞错了,改完后没问题了 :heart:

谢谢大佬,这个token应该是我复制错了,请求/api/v3/get-profile接口时加上另一位大佬说的x-authing-app-id后就调通了