Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sib-auth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Framework
sib-auth
Commits
b679f44e
Commit
b679f44e
authored
5 years ago
by
Clément
Browse files
Options
Downloads
Patches
Plain Diff
update: getUser() return ressource
parent
94d1519d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Resolve "Replace sib-oidc with solid-auth"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.html
+14
-7
14 additions, 7 deletions
index.html
sib-auth-provider.js
+2
-9
2 additions, 9 deletions
sib-auth-provider.js
sib-auth.js
+16
-23
16 additions, 23 deletions
sib-auth.js
with
32 additions
and
39 deletions
index.html
+
14
−
7
View file @
b679f44e
...
...
@@ -26,17 +26,20 @@
<sib-auth>
<sib-auth-provider
data-authority=
"http://127.0.0.1:8000/"
data-authority=
"https://api.test-paris.happy-dev.fr/"
data-client_id=
"234528"
data-id=
"paris"
>
</sib-auth-provider>
<sib-auth-provider
data-authority=
"http://127.0.0.1:8000/"
data-authority=
"https://api.test-paris.happy-dev.fr/"
data-client_id=
"234528"
data-id=
"paris2"
>
</sib-auth-provider>
</sib-auth>
<script>
reset
.
onclick
=
()
=>
{
window
.
sessionStorage
.
clear
();
...
...
@@ -47,7 +50,7 @@
</script>
<script
type=
"module"
>
import
{
SIBBase
}
from
'
https://unpkg.com/@startinblox/core@0.7
'
;
import
{
SIBBase
,
store
}
from
'
https://unpkg.com/@startinblox/core@0.7
'
;
class
TestComponent
extends
SIBBase
{
async
connectedCallback
()
{
...
...
@@ -70,13 +73,17 @@
}
async
update
()
{
const
user
=
await
this
.
getUser
();
if
(
user
)
{
result
.
innerHTML
=
`Bonjour
${
user
}
!`
;
}
else
{
let
user
=
await
this
.
getUser
();
if
(
!
user
)
{
result
.
innerHTML
=
`Vous n'êtes pas connecté !`
;
return
;
}
user
=
await
store
.
get
(
user
);
console
.
log
(
user
);
result
.
innerHTML
=
`Bonjour
${
user
.
username
}
!`
;
}
empty
(){}
populate
(){}
}
customElements
.
define
(
'
sib-test
'
,
TestComponent
);
</script>
...
...
This diff is collapsed.
Click to expand it.
sib-auth-provider.js
+
2
−
9
View file @
b679f44e
...
...
@@ -19,24 +19,17 @@ class SIBAuthProvider extends HTMLElement {
* with the params set in the component, render view
*/
async
connectedCallback
()
{
const
{
authority
,
id
}
=
this
.
dataset
;
// eslint-disable-line camelcase
const
{
id
}
=
this
.
dataset
;
// eslint-disable-line camelcase
this
.
id
=
id
;
this
.
render
(
this
.
dataset
);
}
/** @function
* @name disconnectedCallback
* Remove manager
*/
disconnectedCallback
()
{
}
/** @function
* @name login
* Start login procedure
* @param {SIBAuth} parent - SIBAuth parent instance
*/
async
login
(
parent
)
{
async
login
()
{
auth
.
login
(
this
.
dataset
.
authority
);
}
...
...
This diff is collapsed.
Click to expand it.
sib-auth.js
+
16
−
23
View file @
b679f44e
import
auth
from
'
https://dev.jspm.io/solid-auth-client
'
;
import
{
Helpers
,
SIBBase
}
from
'
https://unpkg.com/@startinblox/core@0.7
'
;
import
{
Helpers
,
SIBBase
}
from
'
https://unpkg.com/@startinblox/core@0.7
'
;
const
baseUrl
=
import
.
meta
.
url
.
replace
(
/
\/[^/]
*$/
,
''
);
Helpers
.
importCSS
(
`
${
baseUrl
}
/sib-auth.css`
);
...
...
@@ -29,7 +29,7 @@ class SIBAuth extends HTMLElement {
this
.
install
();
// this.processState();
if
(
await
this
.
getUserWebId
())
{
this
.
dispatchUserInfo
(
this
.
getUserWebId
()
);
this
.
dispatchUserInfo
();
}
}
...
...
@@ -38,8 +38,7 @@ class SIBAuth extends HTMLElement {
* Clear state and user, uninstall
*/
disconnectedCallback
()
{
solid
.
auth
.
logout
()
.
then
(()
=>
alert
(
'
Goodbye!
'
));
auth
.
logout
();
// .then(() => alert('Goodbye!'));
this
.
uninstall
();
}
...
...
@@ -51,7 +50,11 @@ class SIBAuth extends HTMLElement {
install
()
{
SIBBase
.
prototype
.
login
=
()
=>
this
.
login
();
SIBBase
.
prototype
.
logout
=
()
=>
this
.
logout
();
SIBBase
.
prototype
.
getUser
=
()
=>
this
.
getUserWebId
();
SIBBase
.
prototype
.
getUser
=
async
()
=>
{
const
id
=
await
this
.
getUserWebId
();
if
(
!
id
)
return
null
;
return
{
'
@id
'
:
id
};
};
this
.
bindUserObserver
=
new
MutationObserver
((
mutations
)
=>
{
mutations
.
forEach
((
mutation
)
=>
{
if
(
mutation
.
type
===
'
attributes
'
)
{
...
...
@@ -139,7 +142,7 @@ class SIBAuth extends HTMLElement {
* Try to get user, the if a state is set, call the appropriate provider
*/
async
processState
()
{
const
{
provider
}
=
this
.
getState
();
const
{
provider
}
=
this
.
getState
();
const
providerElement
=
this
.
getProvider
(
provider
);
if
(
providerElement
)
{
this
.
callProvider
(
providerElement
,
'
processState
'
,
this
);
...
...
@@ -152,18 +155,10 @@ class SIBAuth extends HTMLElement {
* Try to replace data-src by userWebId iri on [bind-user] elements
*/
// eslint-disable-next-line class-methods-use-this
async
dispatchUserInfo
(
id
)
{
id
=
await
id
;
console
.
log
(
'
dispath
'
+
id
)
async
dispatchUserInfo
()
{
const
processDOM
=
async
()
=>
{
const
elements
=
document
.
querySelectorAll
(
'
[bind-user]
'
);
elements
.
forEach
(
element
=>
this
.
applyUser
(
element
));
/*
const elements = document.querySelectorAll(`[bind-user]:not([data-src="${id}"])`);
elements.forEach((element) => {
element.setAttribute('data-src', id);
});
*/
};
// check document state and add a hook on DOMContentLoaded if needed
if
(
document
.
readyState
===
'
loading
'
)
{
...
...
@@ -190,17 +185,15 @@ class SIBAuth extends HTMLElement {
* Return User or undefined
* @return {User}
*/
// eslint-disable-next-line class-methods-use-this
getUserWebId
()
{
return
new
Promise
((
resolve
,
error
)
=>
{
auth
.
trackSession
(
session
=>
{
return
new
Promise
((
resolve
)
=>
{
auth
.
trackSession
(
(
session
)
=>
{
if
(
!
session
)
{
console
.
log
(
'
The user is not logged in
'
)
return
resolve
(
null
);
}
else
{
console
.
log
(
`The user is
${
session
.
webId
}
`
)
return
resolve
(
session
.
webId
)
}
})
return
resolve
(
session
.
webId
);
});
});
}
...
...
@@ -221,7 +214,7 @@ class SIBAuth extends HTMLElement {
* Try to logout if favorite provider is set
*/
logout
()
{
auth
.
logout
().
then
(()
=>
this
.
dispatchUserInfo
())
auth
.
logout
().
then
(()
=>
this
.
dispatchUserInfo
())
;
}
/** @function
...
...
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