Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Géocontrib Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GéoContrib
Géocontrib Frontend
Commits
28f99a9d
Commit
28f99a9d
authored
1 year ago
by
Timothee P
Browse files
Options
Downloads
Patches
Plain Diff
Call SSO login with a redirect url and open it after login
parent
23b4a6ad
No related branches found
No related tags found
1 merge request
!780
REDMINE_ISSUE-19725 | Redirection vers la page de connexion du portail MRN si l'utilisateur n'est pas connecté
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/router/index.js
+10
-5
10 additions, 5 deletions
src/router/index.js
src/store/index.js
+60
-16
60 additions, 16 deletions
src/store/index.js
with
70 additions
and
21 deletions
src/router/index.js
+
10
−
5
View file @
28f99a9d
...
@@ -130,11 +130,16 @@ const routes = [
...
@@ -130,11 +130,16 @@ const routes = [
query
[
'
feature_type_slug
'
]
=
slug_type_signal
;
// set feature_type slug in query
query
[
'
feature_type_slug
'
]
=
slug_type_signal
;
// set feature_type slug in query
}
}
const
offset
=
await
featureAPI
.
getFeaturePosition
(
slug
,
slug_signal
,
query
);
const
offset
=
await
featureAPI
.
getFeaturePosition
(
slug
,
slug_signal
,
query
);
next
({
if
(
offset
)
{
name
:
'
details-signalement-filtre
'
,
next
({
params
:
{
slug
},
name
:
'
details-signalement-filtre
'
,
query
:
{
...
query
,
offset
}
params
:
{
slug
},
});
query
:
{
...
query
,
offset
}
});
}
else
{
store
.
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
'
Désolé, une erreur est survenue pendant la recherche du signalement
'
,
level
:
'
negative
'
});
next
({
path
:
'
/
'
});
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'
error
'
,
error
);
console
.
error
(
'
error
'
,
error
);
store
.
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
`Désolé, une erreur est survenue pendant la recherche du signalement -
${
error
}
`
,
level
:
'
negative
'
});
store
.
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
`Désolé, une erreur est survenue pendant la recherche du signalement -
${
error
}
`
,
level
:
'
negative
'
});
...
...
This diff is collapsed.
Click to expand it.
src/store/index.js
+
60
−
16
View file @
28f99a9d
...
@@ -183,33 +183,71 @@ export default new Vuex.Store({
...
@@ -183,33 +183,71 @@ export default new Vuex.Store({
});
});
}
}
},
},
/**
* Action to retrieve user information.
* - If a token is present in the URL, it indicates a Single Sign-On (SSO) attempt,
* in which case it logs out the user (if logged in) and connects via SSO with the token.
* Otherwise, it fetches user information from the Django API endpoint:
* - If no user is logged AND if the login should be done through SSO with a redirect,
* it naviguates to the login plateform, afterwards the user will be redirected with the token and the original url to open in geocontrib
* - Else it displays a message that the user is not logged but can still access the app as an anonymous user.
*/
async
GET_USER_INFO
({
state
,
commit
,
dispatch
})
{
async
GET_USER_INFO
({
state
,
commit
,
dispatch
})
{
const
token
=
new
URLSearchParams
(
window
.
location
.
search
).
get
(
'
token
'
);
// Extract token from URL query parameters
if
(
token
&&
this
.
state
.
configuration
.
VUE_APP_LOGIN_URL
)
{
const
searchParams
=
new
URLSearchParams
(
window
.
location
.
search
);
// if user was previously connected through SSO, make sure he's logout before connecting through SSO, in case user changed
const
token
=
searchParams
.
get
(
'
token
'
);
const
url_redirect
=
searchParams
.
get
(
'
url_redirect
'
);
// Check if token exists and SSO login URL is configured
if
(
token
&&
state
.
configuration
.
VUE_APP_LOGIN_URL
)
{
// If user was previously connected through SSO, ensure they are logged out before reconnecting through SSO, in case user changed
await
dispatch
(
'
LOGOUT
'
);
await
dispatch
(
'
LOGOUT
'
);
dispatch
(
'
CONNECT_SSO_WITH_TOKEN
'
,
token
);
dispatch
(
'
CONNECT_SSO_WITH_TOKEN
'
,
{
token
,
url_redirect
}
);
}
else
if
(
!
state
.
user
)
{
}
else
if
(
!
state
.
user
)
{
// If user infos are not set, try to fetch them
axios
axios
.
get
(
`
${
this
.
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
user_info/`
)
.
get
(
`
${
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
user_info/`
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
// Update the user state with received user data
if
(
response
&&
response
.
status
===
200
)
{
if
(
response
&&
response
.
status
===
200
)
{
const
user
=
response
.
data
.
user
;
const
user
=
response
.
data
.
user
;
commit
(
'
SET_USER
'
,
user
);
commit
(
'
SET_USER
'
,
user
);
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
(()
=>
{
console
.
error
(
err
);
// If the instance is set to accept login with redirection
commit
(
'
DISPLAY_MESSAGE
'
,
{
if
(
state
.
configuration
.
VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT
)
{
comment
:
`Vous n'êtes pas connecté actuellement.
commit
(
'
DISPLAY_MESSAGE
'
,
{
Vous pouvez accéder à l'application en tant qu'utilisateur anonyme`
comment
:
'
Vous allez être redirigé vers la plateforme de connexion.
'
});
});
// Prepare the url to redirect with vue-router that prefix the url with DOMAIN+BASE_URL
let
urlRedirect
=
window
.
location
.
href
;
let
substringToRemove
=
state
.
configuration
.
BASE_URL
;
// Find the index of the string to remove
let
index
=
urlRedirect
.
indexOf
(
substringToRemove
);
// If found, keep only the remaining part after the substring to remove
if
(
index
!==
-
1
)
{
urlRedirect
=
urlRedirect
.
substring
(
index
+
substringToRemove
.
length
);
}
// Call the SSO login plateform with url to redirect after login
window
.
open
(
`
${
state
.
configuration
.
VUE_APP_SSO_LOGIN_URL_WITH_REDIRECT
}
/?url_redirect=
${
urlRedirect
}
`
,
'
_self
'
);
}
else
{
// If the user is not logged in, display an info message
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
`Vous n'êtes pas connecté actuellement.
Vous pouvez accéder à l'application en tant qu'utilisateur anonyme`
});
}
});
});
}
}
},
},
/**
async
CONNECT_SSO_WITH_TOKEN
({
state
,
commit
,
dispatch
},
token
)
{
* Action to connect user through SSO with a token.
* If the app was opened with a token in the url, it attempts a login,
* if the login is succesfull, it set the user in the state
* and retrieve information that would have been retrieved in GET_USER_INFO when logged.
* If the url contained a url to redirect, it calls the router to open this page.
*/
async
CONNECT_SSO_WITH_TOKEN
({
state
,
commit
,
dispatch
},
{
token
,
url_redirect
})
{
axios
axios
.
get
(
`
${
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
login-token/?token=
${
token
}
`
)
.
get
(
`
${
state
.
configuration
.
VUE_APP_DJANGO_API_BASE
}
login-token/?token=
${
token
}
`
)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
...
@@ -219,15 +257,21 @@ export default new Vuex.Store({
...
@@ -219,15 +257,21 @@ export default new Vuex.Store({
dispatch
(
'
GET_USER_LEVEL_PROJECTS
'
);
dispatch
(
'
GET_USER_LEVEL_PROJECTS
'
);
dispatch
(
'
GET_USER_LEVEL_PERMISSIONS
'
);
dispatch
(
'
GET_USER_LEVEL_PERMISSIONS
'
);
commit
(
'
DISPLAY_MESSAGE
'
,
{
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
`Vous êtes maintenant connecté
${
user
.
first_name
}
${
user
.
last_name
}
`
,
level
:
'
positive
'
comment
:
`Vous êtes maintenant connecté
${
user
.
first_name
}
${
user
.
last_name
}
`
,
level
:
'
positive
'
});
});
dispatch
(
'
projects/GET_PROJECTS
'
);
dispatch
(
'
projects/GET_PROJECTS
'
);
if
(
url_redirect
)
{
// catch error from the router, because of second redirection to feature when call with a feature's id
router
.
push
(
url_redirect
).
catch
((
e
)
=>
e
);
}
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
error
(
err
);
console
.
error
(
err
);
commit
(
'
DISPLAY_MESSAGE
'
,
{
commit
(
'
DISPLAY_MESSAGE
'
,
{
comment
:
'
La connexion a échoué.
'
,
level
:
'
negative
'
comment
:
'
La connexion a échoué.
'
,
level
:
'
negative
'
});
});
});
});
},
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment