dqy1265 2018-01-28 16:10
浏览 20
已采纳

Laravel auth0用户搜索返回完整列表

I have the following piece of code:

$auth0Api = new Management(env('AuthToken'), env('Auth0Domain'));    
$user = $auth0Api->users->search([ "user_id" => "google-oauth2|103122844576645532487"]);

The point of this is to return a single user with the given id

However, whenever I call this I get the full list of my users.

Can anyone tell me what im doing wrong?

  • 写回答

1条回答 默认 最新

  • douli2063 2018-01-28 17:20
    关注

    According to the documentation for Auth0 search they use Lucene Query Syntax, which means an Auth0 search query for google-oauth2 user with the id of 103122844576645532487 should look like this:

    identities.provider:"google-oauth2" AND user_id:"103122844576645532487"
    

    The PHP SDK you are using assembles the request to the API for you under the hood based on key/values provided through a withParam method. The search method you are using takes your parameters (['user_id' => '...']) and passes them to withParam, then your request is executed.

    Your search([...]) code is translating into the following API request:

    /api/v2/users?user_id="google-oauth2|10312284457664553248"
    

    However, the API does not support a user_id parameter on the api/v2/users endpoint and your request is being executed as api/v2/users, which is the request to return all users. This is why you're receiving all of your users: you are not (correctly) passing a search query.

    You need to specifically include the q (query) parameter when building your search, and that parameter should equal a valid Lucene Query.

    $auth0Api->users->search([
        'q' => 'identities.provider:"google-oauth2" AND user_id:"103122844576645532487"'
    ]);
    

    This will search for users where their identity provider is google-oauth2 and their user_id is 103122844576645532487.

    You can read the documentation for the api/v2/users method here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?