Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

OpenID Implementation#194

Open
chrismgray wants to merge 19 commits into4clojure:developfrom
chrismgray:openid
Open

OpenID Implementation#194
chrismgray wants to merge 19 commits into4clojure:developfrom
chrismgray:openid

Conversation

@chrismgray
Copy link

This branch implements OpenID for 4clojure, affecting issue #33. The
OpenID library used is Stephen Lindsay's clj-openid, which is
available here, but
unfortunately is not yet on clojars.

I tried to keep things as backwards-compatible as possible, so the
code adds a bit of complexity.

There are two ways that OpenIDs can be used: most simply, a user can
log in with an OpenID. In this case, the only thing identifying the
user is the OpenID URL (i.e., there is no email or username).
Alternatively, a user with an existing username can associate an
OpenID with the username. In that case, the user can log in using the
OpenID, but in all other respects should have the same experience as
if he or she had logged in the normal way.

There are a few known issues with this code. First, I have not
thought a lot about the implications of what happens if two users have
access to the same OpenID. This might allow the second user to
"steal" the first user's account and solutions. It seems to me that
this problem is on par with a user giving his or her password away
(i.e., it's more the user's problem than ours). The second issue is
that OpenID has methods for requesting users' information (such as
avatar, email, etc.), but those do not seem to be exposed by
clj-openid, so can not be used by us. One final known issue is that I
got tired of trying to figure out how to use destructuring on the
request parameters in the openid-callback route (at the end of
login.clj) and just got the needed parameters "by hand". This could
be cleaned up by someone who uses destructuring more than I do.

This code has been tested to an extent -- both logging in only with an
OpenID and by associating an OpenID with a normal account -- but
should obviously be tested at a larger scale before being put into
production.

This doesn't actually add the user to the database yet, but it does
validate that the user's OpenID is good.
Success on receiving an OpenID now mimics the behavior of receiving a
valid username and password.
This is a rather large update that allows users with existing accounts
to associate an OpenID with their current account.  When a user logs
in, the :user returned by session/get-session is now a map, but this
is made backwards-compatible by most of the utility functions
accepting either a string or a map.
(user-attribute :foo) does not return a map, it just returns the attribute.
If the user only has an OpenID, then we need to URLEncode the link to
his or her profile page
mark-completed is never called with the optional user variable, so I
got rid of it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea with user-attribute is that you'd just (def user-id (user-attribute :_id)) once, and then later you can just call (user-id some-user-name). Doing it in-place all over is weird; it actually shouldn't even have been made public.

Factors out #(or (:user %) (:openid %)) pattern.
Put the cond inside the where clause of the database fetch.  The one
thing I don't like about this is that if these functions are passed an
invalid object (such as a map without :user or :openid), then we will
have a situation where we do (fetch-one :users :where nil), which will
incorrectly return a result.  Perhaps we should add an :else to these
conds which looks for something we know not to be in the database.
@chrismgray
Copy link
Author

The latest commits to this branch address the concerns that @amalloy had.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants