-
Couldn't load subscription status.
- Fork 11
Resync to upstream/master (fix segfault in webapp.d + return bool from login()) #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,19 @@ class OAuthWebapp | |
| { | ||
| version (Have_vibe_d_web) @noRoute: | ||
|
|
||
| private OAuthSession loadSessionToContext(scope HTTPServerRequest req, immutable OAuthSettings settings) @safe | ||
| in { | ||
| assert(settings !is null, "Settings can't be null"); | ||
| } | ||
| body | ||
| { | ||
| auto session = OAuthSession.load(settings, req.session); | ||
| () @trusted { | ||
| req.context["oauth.session"] = session; | ||
| } (); | ||
| return session; | ||
| } | ||
|
|
||
| /++ | ||
| Check if a request is from a logged in user | ||
|
|
||
|
|
@@ -49,13 +62,9 @@ class OAuthWebapp | |
| if (!req.session) | ||
| return false; | ||
|
|
||
| if (auto session = | ||
| settings ? OAuthSession.load(settings, req.session) : null) | ||
| if (settings !is null) | ||
| { | ||
| () @trusted { | ||
| req.context["oauth.session"] = session; | ||
| } (); | ||
|
|
||
| loadSessionToContext(req, settings); | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -82,8 +91,11 @@ class OAuthWebapp | |
| settings = The OAuth settings that apply to this _login attempt | ||
| scopes = (Optional) An array of identifiers specifying the scope of | ||
| the authorization requested. | ||
| Returns: `true` if a OAuth session was obtained and | ||
| `false` if no OAuth session is present and a redirect to an | ||
| OAuth provider will happen. | ||
| +/ | ||
| void login( | ||
| bool login( | ||
| scope HTTPServerRequest req, | ||
| scope HTTPServerResponse res, | ||
| immutable OAuthSettings settings, | ||
|
|
@@ -100,24 +112,27 @@ class OAuthWebapp | |
|
|
||
| auto session = settings.userSession( | ||
| req.session, req.query["state"], req.query["code"]); | ||
|
|
||
| return true; | ||
| } | ||
| else | ||
| { | ||
| if (!req.session) | ||
| req.session = res.startSession(); | ||
|
|
||
| res.redirect(settings.userAuthUri(req.session, extraParams, scopes)); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /// ditto | ||
| void login( | ||
| bool login( | ||
| scope HTTPServerRequest req, | ||
| scope HTTPServerResponse res, | ||
| immutable OAuthSettings settings, | ||
| in string[] scopes) @safe | ||
| { | ||
| login(req, res, settings, null, scopes); | ||
| return login(req, res, settings, null, scopes); | ||
| } | ||
|
|
||
| /++ | ||
|
|
@@ -131,12 +146,13 @@ class OAuthWebapp | |
|
|
||
| Params: | ||
| req = the request to get the relevant session for | ||
| settings = The OAuth settings that apply to this _login attempt | ||
|
|
||
| Returns: The session associated to req, or `null` if no | ||
| session was found. | ||
| +/ | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for As mentioned in the documentation comment, |
||
| in | ||
| { | ||
| try | ||
|
|
@@ -147,15 +163,18 @@ class OAuthWebapp | |
| body | ||
| { | ||
| try | ||
| { | ||
| if (auto pCM = "oauth.session" in req.context) | ||
| return pCM.get!OAuthSession; | ||
| else | ||
| return loadSessionToContext(req, settings); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even with this, there's still the possibility of |
||
| } | ||
| catch (Exception e) | ||
| { | ||
| import vibe.core.log : logError; | ||
| logError("OAuth: Exception occurred while reading request " ~ | ||
| "context: %s", e.toString()); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would introduce a serious bug. Should only return
trueif a session is available.