Skip to content

Commit e324c4e

Browse files
author
root
committed
fix : setups the redirect for the login instead of popup to address bug introduced by this security patch openstreetmap/openstreetmap-website@2ff4d6a
1 parent 9364882 commit e324c4e

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

core/settings/contrib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
SOCIAL_AUTH_OPENSTREETMAP_LOGIN_URL = "/osm/login/"
4646
SOCIAL_AUTH_OPENSTREETMAP_OAUTH2_KEY = os.getenv("OSM_API_KEY")
4747
SOCIAL_AUTH_OPENSTREETMAP_OAUTH2_SECRET = os.getenv("OSM_API_SECRET")
48-
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/"
48+
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/authorized"
4949
SOCIAL_AUTH_LOGIN_ERROR_URL = "/osm/error"
5050
SOCIAL_AUTH_URL_NAMESPACE = "osm"
5151
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ["username", "first_name", "email"]

ui/app/actions/meta.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (window.OAUTH_CLIENT_ID == null) {
3232

3333
const oauthConfig = {
3434
// url: window.EXPORTS_API_URL + "/o/openstreetmap_oauth2",
35-
url: window.EXPORTS_API_URL + "/o/authorize?approval_prompt=auto",
35+
url: window.EXPORTS_API_URL + "/o/authorize?approval_prompt=auto&response_type=token",
3636
client: window.OAUTH_CLIENT_ID,
3737
redirect: `${window.location.protocol}//${hostname}/authorized`
3838
};
@@ -95,7 +95,13 @@ export const fetchGroups = () => (dispatch, getState) => {
9595
);
9696
};
9797

98-
export const login = () => _login(oauthConfig);
98+
export const login = () => {
99+
const { url, client, redirect } = oauthConfig;
100+
window.location.href =
101+
url +
102+
`&client_id=${client}` +
103+
`&redirect_uri=${encodeURIComponent(redirect)}`;
104+
};
99105

100106
export const loginSuccess = (token, expiresAt) => dispatch =>
101107
dispatch({

ui/app/components/Authorized.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
import React from "react";
2-
import { FormattedMessage } from "react-intl";
3-
4-
export default () =>
5-
<div>
6-
<FormattedMessage
7-
id="ui.authorized.thank_you"
8-
defaultMessage="Thank you for authorizing!"
9-
/>
10-
</div>;
2+
import { connect } from "react-redux";
3+
import { withRouter } from "react-router-dom";
4+
import { loginSuccess } from "../actions/meta";
5+
6+
class Authorized extends React.Component {
7+
componentDidMount() {
8+
// grab the hash fragment (e.g. "#access_token=…&expires_in=…")
9+
const hash = window.location.hash.replace(/^#/, "");
10+
const params = new URLSearchParams(hash);
11+
const token = params.get("access_token");
12+
const expiresIn = params.get("expires_in");
13+
14+
if (token) {
15+
16+
const expiresAt = expiresIn
17+
? Date.now() + parseInt(expiresIn, 10) * 1000
18+
: null;
19+
20+
21+
this.props.loginSuccess(token, expiresAt);
22+
23+
window.location.hash = "";
24+
this.props.history.replace("/");
25+
} else {
26+
// no token? bounce back to login/start
27+
this.props.history.replace("/");
28+
}
29+
}
30+
31+
render() {
32+
return null;
33+
}
34+
}
35+
36+
export default withRouter(
37+
connect(
38+
null,
39+
{ loginSuccess }
40+
)(Authorized)
41+
);

ui/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def authorized(request):
2323
# be logged into the site (and it will be confusing if they are, since
2424
# "logging out" of the UI just drops the auth token)
2525
auth_logout(request)
26-
return render(request, "ui/authorized.html")
26+
return v3(request)
27+
# return render(request, "ui/authorized.html")
2728

2829

2930
def login(request):

0 commit comments

Comments
 (0)