This repository was archived by the owner on Dec 30, 2025. It is now read-only.
Open
Conversation
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
src/foreclojure/problems.clj
Outdated
Member
There was a problem hiding this comment.
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.
Author
|
The latest commits to this branch address the concerns that @amalloy had. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.