1
0
Fork 0
mirror of https://github.com/Luzifer/past3.git synced 2024-12-22 20:31:16 +00:00

Auto-refresh AWS credentials to prevent save errors

This commit is contained in:
Knut Ahlers 2017-01-21 00:17:23 +01:00
parent 5e25d393df
commit 012c377734
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -49,11 +49,18 @@ $ ->
signinCallback = (authResult) ->
if authResult.Zi.id_token
getAWSCredentials authResult.Zi.id_token
window.past3_credential_refresh = window.setInterval () ->
if new Date(AWS.config.credentials.expireTime - 300000) < new Date()
refreshGoogleLogin()
, 10000
getAWSCredentials = (googleIDToken) ->
AWS.config.credentials = new AWS.CognitoIdentityCredentials
IdentityPoolId: window.past3_config.identity_pool_id
Logins:
'accounts.google.com': authResult.Zi.id_token
'accounts.google.com': googleIDToken
AWS.config.credentials.get () ->
$('#signin').modal 'hide'
@ -172,3 +179,8 @@ error = (err) ->
ed = $('#errorDisplay')
ed.find('.alert').text err
ed.show()
refreshGoogleLogin = () ->
console.log "Refreshing Google login / AWS credentials to keep editor working"
gapi.auth2.getAuthInstance().currentUser.get().reloadAuthResponse().then (data) ->
getAWSCredentials data.id_token