-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OAuth setup simplification #26
Comments
OIDC aims at simplifying this by adding all these (and some more options) to a configuration file to a well known location, see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig Examples
ImplementationGiven that, we could provide an API such as the following: use web\auth\SessionBased;
use web\auth\oauth\Provider;
$oidc= new Provider(
'https://login.windows.net/common/',
new BySecret('613aacd1f95ce7ee1b04', '...'),
);
$auth= new SessionBased($oidc->flow(), $sessions, function($user) {
// Potentially include user field mapping logic...
return $users->upsert($user);
}); ...which would the mean only having to configure 1 URL instead of 3. CaveatHowever, not all sites support this configuration, e.g. GitHub, see https://stackoverflow.com/questions/52157568/what-is-github-well-known-openid-configuration-url |
Another potential for compressing this is introducing a specialized OAuth URI: Syntax
Examples
CaveatsThis breaks for Facebook when using https://www.facebook.com/v18.0/dialog/oauth as authorization endpoint and https://graph.facebook.com/v18.0/oauth/access_token as token endpoint as documented here. As seen above, this does not need to be a problem, but requires extra cognitive load for developers! |
Other libraries such as The PHPLeague OAuth client go down the road of encapsulating these well-known URLs inside implementing classes, see e.g. https://github.com/thephpleague/oauth2-facebook/blob/main/src/Provider/Facebook.php. This leads to hundreds of small libraries like the ones listed on their third-party page, with the problem of them becoming outdated quickly. |
Fetching the user info is a small improvement to the API, see #27: - use web\auth\{AuthenticationError, SessionBased};
+ use web\auth\SessionBased;
use web\auth\oauth\OAuth2Flow;
$flow= new OAuth2Flow(/* shortened for brevity */);
- $auth= new SessionBased($flow, $sessions, function($client) {
- $res= $client->fetch('https://graph.microsoft.com/v1.0/me');
- if ($res->status() >= 400) throw new AuthenticationError('Unexpected status '.$res->status());
- return $res->value();
- });
+ $auth= new SessionBased($flow, $sessions, $flow->fetchUser('https://graph.microsoft.com/v1.0/me')); |
For an example, see thekid/crews#3 |
Currently, this is the typical code setup inside a web applications' routes() method:
If I want to make this configurable and integrate well with several services, there's a lot to do:
👉 This boils down to almost 10 configuration options that have to be set in order to get an OAuth workflow running!
The text was updated successfully, but these errors were encountered: