Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grdf_konnector
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
grdf_konnector
Commits
207dcb4f
Commit
207dcb4f
authored
2 years ago
by
Bastien DUMONT
Browse files
Options
Downloads
Patches
Plain Diff
chore: bump manifest to 1.0.5
parent
84e9bae8
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
manifest.konnector
+1
-1
1 addition, 1 deletion
manifest.konnector
src/onDeleteAccount.js
+88
-88
88 additions, 88 deletions
src/onDeleteAccount.js
yarn.lock
+805
-10
805 additions, 10 deletions
yarn.lock
with
894 additions
and
99 deletions
manifest.konnector
+
1
−
1
View file @
207dcb4f
{
{
"version": "1.0.
4
",
"version": "1.0.
5
",
"name": "GRDF",
"name": "GRDF",
"type": "konnector",
"type": "konnector",
"language": "node",
"language": "node",
...
...
This diff is collapsed.
Click to expand it.
src/onDeleteAccount.js
+
88
−
88
View file @
207dcb4f
const
{
cozyClient
,
log
}
=
require
(
"
cozy-konnector-libs
"
);
const
{
cozyClient
,
log
}
=
require
(
'
cozy-konnector-libs
'
)
const
getAccountId
=
require
(
"
./helpers/getAccountId
"
);
const
getAccountId
=
require
(
'
./helpers/getAccountId
'
)
const
getAccountRev
=
require
(
"
./helpers/getAccountRev
"
);
const
getAccountRev
=
require
(
'
./helpers/getAccountRev
'
)
const
getAccountSecret
=
require
(
"
./helpers/getAccountSecret
"
);
const
getAccountSecret
=
require
(
'
./helpers/getAccountSecret
'
)
const
moment
=
require
(
"
moment
"
);
const
moment
=
require
(
'
moment
'
)
require
(
"
moment-timezone
"
);
require
(
'
moment-timezone
'
)
moment
.
locale
(
"
fr
"
);
// set the language
moment
.
locale
(
'
fr
'
)
// set the language
moment
.
tz
.
setDefault
(
"
Europe/Paris
"
);
// set the timezone
moment
.
tz
.
setDefault
(
'
Europe/Paris
'
)
// set the timezone
async
function
onDeleteAccount
(
accountId
)
{
async
function
onDeleteAccount
(
accountId
)
{
const
accountRev
=
getAccountRev
()
;
const
accountRev
=
getAccountRev
()
if
(
accountRev
)
{
if
(
accountRev
)
{
try
{
try
{
let
body
=
""
;
let
body
=
''
let
access_token
=
""
;
let
access_token
=
''
body
=
await
cozyClient
.
fetchJSON
(
body
=
await
cozyClient
.
fetchJSON
(
"
GET
"
,
'
GET
'
,
`/data/io.cozy.accounts/
${
accountId
}
?rev=
${
accountRev
}
`
`/data/io.cozy.accounts/
${
accountId
}
?rev=
${
accountRev
}
`
)
;
)
if
(
body
.
oauth
.
access_token
)
{
if
(
body
.
oauth
.
access_token
)
{
access_token
=
body
.
oauth
.
access_token
;
access_token
=
body
.
oauth
.
access_token
}
else
{
}
else
{
throw
new
Error
(
throw
new
Error
(
"
cozyClient.fetchJson account_rev has encountered an error
"
'
cozyClient.fetchJson account_rev has encountered an error
'
)
;
)
}
}
if
(
moment
().
diff
(
body
.
oauth
.
expires_at
)
>
0
)
{
if
(
moment
().
diff
(
body
.
oauth
.
expires_at
)
>
0
)
{
// token is expired, need a new one. grdf does not provide a refresh token
// token is expired, need a new one. grdf does not provide a refresh token
// so we request a new one from a client_credentials query
// so we request a new one from a client_credentials query
// first we fetch credentials secrets from account-type
// first we fetch credentials secrets from account-type
const
accountSecret
=
getAccountSecret
()
;
const
accountSecret
=
getAccountSecret
()
if
(
accountSecret
)
{
if
(
accountSecret
)
{
var
myTokenHeaders
=
new
Headers
()
;
var
myTokenHeaders
=
new
Headers
()
myTokenHeaders
.
append
(
myTokenHeaders
.
append
(
"
Content-Type
"
,
'
Content-Type
'
,
"
application/x-www-form-urlencoded
"
'
application/x-www-form-urlencoded
'
)
;
)
var
urlencoded
=
new
URLSearchParams
()
;
var
urlencoded
=
new
URLSearchParams
()
urlencoded
.
append
(
"
grant_type
"
,
"
client_credentials
"
);
urlencoded
.
append
(
'
grant_type
'
,
'
client_credentials
'
)
urlencoded
.
append
(
"
client_id
"
,
accountSecret
.
client_id
)
;
urlencoded
.
append
(
'
client_id
'
,
accountSecret
.
client_id
)
urlencoded
.
append
(
"
client_secret
"
,
accountSecret
.
client_secret
)
;
urlencoded
.
append
(
'
client_secret
'
,
accountSecret
.
client_secret
)
urlencoded
.
append
(
"
scope
"
,
"
/adict/v1
"
);
urlencoded
.
append
(
'
scope
'
,
'
/adict/v1
'
)
var
requestOptionsToken
=
{
var
requestOptionsToken
=
{
method
:
"
POST
"
,
method
:
'
POST
'
,
headers
:
myTokenHeaders
,
headers
:
myTokenHeaders
,
body
:
urlencoded
,
body
:
urlencoded
,
redirect
:
"
follow
"
redirect
:
'
follow
'
}
;
}
access_token
=
await
fetch
(
access_token
=
await
fetch
(
"
https://sofit-sso-oidc.grdf.fr/openam/oauth2/realms/externeGrdf/access_token
"
,
'
https://sofit-sso-oidc.grdf.fr/openam/oauth2/realms/externeGrdf/access_token
'
,
requestOptionsToken
requestOptionsToken
)
)
.
then
(
async
response
=>
{
.
then
(
async
response
=>
{
if
(
response
.
status
!==
200
)
{
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
response
.
status
+
"
-
"
+
response
.
statusText
)
;
throw
new
Error
(
response
.
status
+
'
-
'
+
response
.
statusText
)
}
}
return
response
.
text
()
;
return
response
.
text
()
})
})
.
then
(
result
=>
{
.
then
(
result
=>
{
return
result
.
match
(
/.+/g
).
map
(
s
=>
{
return
result
.
match
(
/.+/g
).
map
(
s
=>
{
result
=
JSON
.
parse
(
s
)
;
result
=
JSON
.
parse
(
s
)
if
(
result
.
access_token
)
{
if
(
result
.
access_token
)
{
return
result
.
access_token
;
return
result
.
access_token
}
}
})
;
})
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
log
(
"
debug
"
,
"
Error from get access_token [onDeleteAccount]
"
);
log
(
'
debug
'
,
'
Error from get access_token [onDeleteAccount]
'
)
throw
error
;
throw
error
})
;
})
}
else
{
}
else
{
throw
new
Error
(
throw
new
Error
(
"
Access Token is expired and konnector failed to get a new one
"
'
Access Token is expired and konnector failed to get a new one
'
)
;
)
}
}
}
}
var
myHeaders
=
new
Headers
()
;
var
myHeaders
=
new
Headers
()
myHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
myHeaders
.
append
(
'
Content-Type
'
,
'
application/json
'
)
myHeaders
.
append
(
"
Accept
"
,
"
application/x-ndjson
"
);
myHeaders
.
append
(
'
Accept
'
,
'
application/x-ndjson
'
)
myHeaders
.
append
(
"
Authorization
"
,
"
Bearer
"
+
access_token
)
;
myHeaders
.
append
(
'
Authorization
'
,
'
Bearer
'
+
access_token
)
var
raw
=
JSON
.
stringify
({
var
raw
=
JSON
.
stringify
({
role_tiers
:
[
"
AUTORISE_CONTRAT_FOURNITURE
"
],
role_tiers
:
[
'
AUTORISE_CONTRAT_FOURNITURE
'
],
etat_droit_acces
:
[
"
Active
"
],
etat_droit_acces
:
[
'
Active
'
],
id_pce
:
[
body
.
oauth_callback_results
.
pce
]
id_pce
:
[
body
.
oauth_callback_results
.
pce
]
})
;
})
var
requestOptions
=
{
var
requestOptions
=
{
method
:
"
POST
"
,
method
:
'
POST
'
,
headers
:
myHeaders
,
headers
:
myHeaders
,
body
:
raw
,
body
:
raw
,
redirect
:
"
follow
"
redirect
:
'
follow
'
}
;
}
let
accessRights
=
await
fetch
(
let
accessRights
=
await
fetch
(
"
https://api.grdf.fr/adict/v1/droits_acces
"
,
'
https://api.grdf.fr/adict/v1/droits_acces
'
,
requestOptions
requestOptions
)
)
.
then
(
async
response
=>
{
.
then
(
async
response
=>
{
if
(
response
.
status
!==
200
)
{
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
response
.
status
+
"
-
"
+
response
.
statusText
)
;
throw
new
Error
(
response
.
status
+
'
-
'
+
response
.
statusText
)
}
}
return
response
.
text
()
;
return
response
.
text
()
})
})
.
then
(
result
=>
{
.
then
(
result
=>
{
return
result
.
match
(
/.+/g
).
map
(
s
=>
{
return
result
.
match
(
/.+/g
).
map
(
s
=>
{
result
=
JSON
.
parse
(
s
)
;
result
=
JSON
.
parse
(
s
)
if
(
result
.
id_droit_acces
!==
null
)
{
if
(
result
.
id_droit_acces
!==
null
)
{
return
result
.
id_droit_acces
;
return
result
.
id_droit_acces
}
}
})
;
})
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
log
(
"
debug
"
,
"
Error from get droits_access
"
);
log
(
'
debug
'
,
'
Error from get droits_access
'
)
throw
error
;
throw
error
})
;
})
// remove unwanted commas
// remove unwanted commas
accessRights
=
accessRights
.
toString
().
replace
(
/,
\s
*$/
,
""
);
accessRights
=
accessRights
.
toString
().
replace
(
/,
\s
*$/
,
''
)
if
(
accessRights
)
{
if
(
accessRights
)
{
var
myDeleteHeaders
=
new
Headers
()
;
var
myDeleteHeaders
=
new
Headers
()
myDeleteHeaders
.
append
(
"
Cache-Control
"
,
"
no-cache
"
);
myDeleteHeaders
.
append
(
'
Cache-Control
'
,
'
no-cache
'
)
myDeleteHeaders
.
append
(
"
Content-Type
"
,
"
application/json
"
);
myDeleteHeaders
.
append
(
'
Content-Type
'
,
'
application/json
'
)
myDeleteHeaders
.
append
(
"
Authorization
"
,
"
Bearer
"
+
access_token
)
;
myDeleteHeaders
.
append
(
'
Authorization
'
,
'
Bearer
'
+
access_token
)
var
deleteRaw
=
JSON
.
stringify
({})
;
var
deleteRaw
=
JSON
.
stringify
({})
var
deleteRequestOptions
=
{
var
deleteRequestOptions
=
{
method
:
"
PATCH
"
,
method
:
'
PATCH
'
,
headers
:
myDeleteHeaders
,
headers
:
myDeleteHeaders
,
body
:
deleteRaw
,
body
:
deleteRaw
,
redirect
:
"
follow
"
redirect
:
'
follow
'
}
;
}
var
url
=
"
https://api.grdf.fr/adict/v1/droit_acces/
"
+
accessRights
;
var
url
=
'
https://api.grdf.fr/adict/v1/droit_acces/
'
+
accessRights
await
fetch
(
url
,
deleteRequestOptions
)
await
fetch
(
url
,
deleteRequestOptions
)
.
then
(
async
response
=>
{
.
then
(
async
response
=>
{
if
(
response
.
status
!==
200
)
{
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
response
.
status
+
"
-
"
+
response
.
statusText
)
;
throw
new
Error
(
response
.
status
+
'
-
'
+
response
.
statusText
)
}
}
return
response
.
text
()
;
return
response
.
text
()
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
log
(
"
debug
"
,
"
Error from delete droits_access
"
);
log
(
'
debug
'
,
'
Error from delete droits_access
'
)
throw
error
;
throw
error
})
;
})
log
(
"
debug
"
,
"
Active consent was successfully removed
"
);
log
(
'
debug
'
,
'
Active consent was successfully removed
'
)
}
else
{
}
else
{
log
(
"
debug
"
,
"
No active consent
"
);
log
(
'
debug
'
,
'
No active consent
'
)
throw
new
Error
(
"
No active access right was found for given user
"
);
throw
new
Error
(
'
No active access right was found for given user
'
)
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
log
(
log
(
"
warn
"
,
'
warn
'
,
`Error while trying to remove grdf consent (for
${
accountRev
}
):
${
err
.
message
}
`
`Error while trying to remove grdf consent (for
${
accountRev
}
):
${
err
.
message
}
`
)
;
)
}
}
}
else
{
}
else
{
throw
new
Error
(
throw
new
Error
(
"
No account revision was found, something went wrong during the deletion of said account
"
'
No account revision was found, something went wrong during the deletion of said account
'
)
;
)
}
}
}
}
const
accountId
=
getAccountId
()
;
const
accountId
=
getAccountId
()
onDeleteAccount
(
accountId
).
then
(
onDeleteAccount
(
accountId
).
then
(
()
=>
{
()
=>
{
log
(
log
(
"
info
"
,
'
info
'
,
`onDeleteAccount: Successfully retrieved grdf account from account doctype.`
`onDeleteAccount: Successfully retrieved grdf account from account doctype.`
)
;
)
},
},
err
=>
{
err
=>
{
log
(
log
(
"
error
"
,
'
error
'
,
`onDeleteAccount: An error occured during getGrdfAccountInfos script:
${
err
.
message
}
`
`onDeleteAccount: An error occured during getGrdfAccountInfos script:
${
err
.
message
}
`
)
;
)
}
}
)
;
)
module
.
exports
=
{
onDeleteAccount
}
;
module
.
exports
=
{
onDeleteAccount
}
This diff is collapsed.
Click to expand it.
yarn.lock
+
805
−
10
View file @
207dcb4f
This diff is collapsed.
Click to expand it.
Bastien DUMONT
@bdumont
mentioned in commit
b2b81fd4
·
2 years ago
mentioned in commit
b2b81fd4
mentioned in commit b2b81fd4dcff85ca88fe96b3dbec057b68478e69
Toggle commit list
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