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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)