File tree Expand file tree Collapse file tree 4 files changed +51
-13
lines changed Expand file tree Collapse file tree 4 files changed +51
-13
lines changed Original file line number Diff line number Diff line change 45
45
SOCIAL_AUTH_OPENSTREETMAP_LOGIN_URL = "/osm/login/"
46
46
SOCIAL_AUTH_OPENSTREETMAP_OAUTH2_KEY = os .getenv ("OSM_API_KEY" )
47
47
SOCIAL_AUTH_OPENSTREETMAP_OAUTH2_SECRET = os .getenv ("OSM_API_SECRET" )
48
- SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/"
48
+ SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/authorized "
49
49
SOCIAL_AUTH_LOGIN_ERROR_URL = "/osm/error"
50
50
SOCIAL_AUTH_URL_NAMESPACE = "osm"
51
51
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ["username" , "first_name" , "email" ]
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ if (window.OAUTH_CLIENT_ID == null) {
32
32
33
33
const oauthConfig = {
34
34
// 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 " ,
36
36
client : window . OAUTH_CLIENT_ID ,
37
37
redirect : `${ window . location . protocol } //${ hostname } /authorized`
38
38
} ;
@@ -95,7 +95,13 @@ export const fetchGroups = () => (dispatch, getState) => {
95
95
) ;
96
96
} ;
97
97
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
+ } ;
99
105
100
106
export const loginSuccess = ( token , expiresAt ) => dispatch =>
101
107
dispatch ( {
Original file line number Diff line number Diff line change 1
1
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
+ ) ;
Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ def authorized(request):
23
23
# be logged into the site (and it will be confusing if they are, since
24
24
# "logging out" of the UI just drops the auth token)
25
25
auth_logout (request )
26
- return render (request , "ui/authorized.html" )
26
+ return v3 (request )
27
+ # return render(request, "ui/authorized.html")
27
28
28
29
29
30
def login (request ):
You can’t perform that action at this time.
0 commit comments