Resync to upstream/master (fix segfault in webapp.d + return bool from login())#9
Resync to upstream/master (fix segfault in webapp.d + return bool from login())#9wilzbach wants to merge 2 commits intothaven:masterfrom
Conversation
thaven
left a comment
There was a problem hiding this comment.
I understand the inconvenience in situations where oauth is not being used to keep track of user logins. Seems sensible to reconsider the naming, and possibly usage, of isLoggedIn. This commit does not seem to solve the problem correctly.
| +/ | ||
| final | ||
| OAuthSession oauthSession(scope HTTPServerRequest req) nothrow @trusted | ||
| OAuthSession oauthSession(scope HTTPServerRequest req, immutable OAuthSettings settings = null) nothrow @trusted |
There was a problem hiding this comment.
The reason for oauthSession to not take a settings parameter, is that it should be possible for multi-provider apps to get the OAuthSession regardless of the settings used to login.
As mentioned in the documentation comment, oauthSession is just a getter to be used only after checking for session availability and validity.
| if (auto pCM = "oauth.session" in req.context) | ||
| return pCM.get!OAuthSession; | ||
| else | ||
| return loadSessionToContext(req, settings); |
There was a problem hiding this comment.
Even with this, there's still the possibility of oauthSession returning null, i.e. when the user did not login with OAuth. So the need for a null-check will always exist, unless a session is known to be available (e.g. isLoggedIn is known to have returned true for this request).
| } (); | ||
|
|
||
| loadSessionToContext(req, settings); | ||
| return true; |
There was a problem hiding this comment.
This would introduce a serious bug. Should only return true if a session is available.
|
Added commit 88e11ac to master. |
So the main problem turned out to be that I use a different method to check for the login state, which means that the session is never added to
req.context. The failure manifested as nasty segfault due to Session being null. Thus, the second commit will add the session toreq.contextas fallback if settings are supplied tooauthSession. In theory,loginshould also have a check for this - maybe inuserAuthUri?The first commit allows to use the result of the
loginfunction, s.t. instead ofWe can write: