Skip to content

Commit

Permalink
Make consumer of user info configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhelmer committed May 21, 2024
1 parent 7b6eca8 commit 1eb9f37
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

// The base URL for the user service
'user_api_base_url' => env('AUTH0_USER_API'),

// The consumer name for the user data
'user_api_consumer' => env('AUTH0_USER_API_CONSUMER', 'auth0'),
];
5 changes: 4 additions & 1 deletion src/GsvAuth0ProviderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function register()

// Register the user service
$this->app->singleton('gsv-auth0-user-service', function () {
return new UserService(config('gsv-auth0-provider.user_api_base_url'));
return new UserService(
config('gsv-auth0-provider.user_api_base_url'),
config('gsv-auth0-provider.user_api_consumer')
);
});

// Open the gates
Expand Down
11 changes: 8 additions & 3 deletions src/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ class UserService
*/
protected $baseUrl;

/**
* @var string
*/
protected $consumer;

/**
* @var string
*/
protected string $token;

public function __construct(?string $baseUrl = null)
public function __construct(?string $baseUrl = null, ?string $consumer = null)
{
$this->baseUrl = $baseUrl;
$this->consumer = $consumer;
}

/**
Expand Down Expand Up @@ -83,8 +89,7 @@ public function fetch()
}

return Http::withToken($this->token)
->withoutVerifying()
->get($this->baseUrl . '/api/users/auth0')
->get(sprintf('%s/api/users/%s', $this->baseUrl, $this->consumer))
->json();
}
}

0 comments on commit 1eb9f37

Please sign in to comment.