-
Notifications
You must be signed in to change notification settings - Fork 32
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
OAuth2/OpenID Connect implementation #270
base: master
Are you sure you want to change the base?
Conversation
If you are going to implement oauth2/openid ... please make an external library. This will get more traction, more visibility and make a better library. Several people would be interested by such library. |
@Drup It depends a few on the users table and I created some tables in OS. |
Of course, there are OS-specific parts that interact with the user tables, but do they have to do with oauth2 really, or just with authentication in general ? |
@Drup I can extract some part which is not OS-specific. Requests, Tokens representation, etc can be in an external library. |
68e414e
to
a342910
Compare
…move some useless comments.
d15801d
to
8713013
Compare
As suggested, I will (later, I don't know when) do an external service for OAuth2.0 and OpenID Connect. |
Don't loose time reviewing now. Lots of things must be done.
It was the first project I did in Ocsigen when I arrived so I suppose I need to change lots of things.
Sorry for the reviewer(s) but it's not something we can do in multiple PR. I will provide test applications.
Description.
This PR implements OAuth2.0 and OpenID Connect (server and client, independent) in ocsigen-start.
OAuth2.0 gives authorizations to external applications to get access to some informations.
For more information about OAuth2.0, see the official website or the RFC 6749. For information about OpenID Connect, see the official website or the RFC.
The implementation is focused on the Authorization code grant but other methods (Implicit grant, Password credentials and Client credentials grant) can be easily implemented independently by using the scopes and tokens module types. The only things which changed are the requests.
This implementation provides typed scopes and tokens, and give the possibility to implement its own scopes (module type
SCOPE
) tokens (module typeIDTOKEN
andTOKEN
).It's based on server-to-server communication:
Os_[connect|oauth2]_client
doesn't mean it's client-side code (compiled in JavaScript) but it's server-side code for the OAuth2.0 client (which is a server).Organization.
For both (OAuth2.0 and OpenID Connect), there is the client and the server side, both are independent from ocsigen-start. By independent from ocsigen-start, it means we can have a service providing an OAuth2.0 server with ocsigen-start and the client is not necessary an ocsigen-start application (thanks @o-marshmallow who tested it).
The opposite (client using ocsigen-start and server not using ocsigen-start) must also be the case, but not tested. The problem with the opposite is lot of OAuth2.0 and OpenID Connect servers (GitHub, GitLab, Twitter, Facebook, etc) don't implement the RFC and this implementation is not entirely configurable (due to GET and POST parameters).
About modules types.
Each server and client defines a
SCOPE
and aTOKEN
module type withCLIENT
orSERVER
module type depending on the purpose. It is necessary to redefine a new interface for each module because we don't have or need the same functions and same fields on tokens if it's an OAuth2.0 client or an OAuth2.0 server. For example, on the OAuth2.0 server, we need to transform the token in a JSON format (which is useless on the client) and on the OAuth2.0 client, we need to parse the JSON into a token (which is useless on the server). And all token server fields are not useful for the client and vice versa.Even if some functions are in both side, I chose to not use
include
: I think it's clearer in this way.OAuth2.0
The client (resp. server) implementation is provided in the files
Os_oauth2_client.eliomi
andOs_oauth2_client.eliom
(resp.Os_oauth2_server.eliomi
andOs_oauth2_server.eliom
).Shared pieces of code like services are in modules
Os_oauth2_shared.eliomi
andOs_oauth2_shared.eliom
.OpenID Connect
The client (resp. server) implementation is provided in the files
Os_connect_client.eliomi
andOs_connect_client.eliom
(resp.Os_connect_server.eliomi
andOs_connect_server.eliom
).As OpenID Connect is using OAuth2.0 protocol, the code for OpenID Connect is smaller and use functions and modules from OAuth2.0 implementation.
Todo
Work ontimeout
andnumber_of_timeout
.timeout
-->cycle_duration
,number_of_timeout
-->number_of_cycle
.Save token in eliom non volatile references.Tokens are saved in a list because as they will be expired aftercycle_duration * number_of_cycle
seconds, it doesn't matter if they are removed while restarting the server. They don't need to be saved in database (except the ID token for OpenID Connect.Os_oauth2_client.eliomi
Os_oauth2_client.eliom
Os_oauth2_server.eliomi
Os_oauth2_server.eliom
Os_oauth2_shared.eliomi
Os_oauth2_shared.eliom
Os_connect_client.eliomi
Os_connect_client.eliom
Os_connect_server.eliomi
Os_connect_server.eliom
Os_db
doc/manual-wiki
. (not a tutorial).ocsigen_start
.cycle_duration * number_of_cycle
.Os_types
.t_of_string
,string_of_t
).counter_of_saved_token
. Remove some information in the module types likecounter_of_saved_token
: it must be in the SERVER implementation.Os_current_user
instead of using aset_userid
function.rpc_resource_owner_decline
-->resource_owner_decline
. Change also the types of the arguments.Fix #10