Skip to content

Commit

Permalink
Merge pull request #92 from javfg/authentication-fixes
Browse files Browse the repository at this point in the history
Authentication fixes
  • Loading branch information
kulmann authored Oct 20, 2021
2 parents efca5d9 + fa224a4 commit 7df5438
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/bugfix-authentication-fixes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Authentication fixes

We've fixed a bug causing the file-picker becoming stuck on the loading spinner when the access token is already expired.

https://github.com/owncloud/file-picker/pull/92
28 changes: 22 additions & 6 deletions src/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Log, User, UserManager, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client'

const AUTH_STORAGE_PREFIX = 'oc_oAuth'

export function initVueAuthenticate(config) {
if (config) {
const storage = config.storage === 'memory' ? new InMemoryWebStorage() : sessionStorage
const storage = config.storage === 'memory' ? new InMemoryWebStorage() : localStorage
const store = new WebStorageStateStore({
prefix: 'oc_oAuth',
prefix: AUTH_STORAGE_PREFIX,
store: storage
})

Expand Down Expand Up @@ -67,27 +69,41 @@ export function initVueAuthenticate(config) {
console.log('UserSignedOut:', arguments)
})

mgr.events.addSilentRenewError(() => {
mgr.clearStaleState(store, 0)
})

return {
authenticate() {
mgr.clearStaleState(store, 0)
return mgr.signinPopup()
},
getToken() {
const storageString = storage.getItem('oc_oAuth' + mgr._userStoreKey)
const storageString = storage.getItem(AUTH_STORAGE_PREFIX + mgr._userStoreKey)

if (storageString) {
const user = User.fromStorageString(storageString)

if (user) {
mgr.events.load(user, false)

return user.access_token
if (user.expired) {
mgr.signinSilent().then((_, reject) => {
if (reject) {
mgr.clearStaleState(store, 0)
return null
}
return user.access_token
})
} else {
return user.access_token
}
}
}

return null
},
getStoredUserObject() {
const storageString = storage.getItem('oc_oAuth' + mgr._userStoreKey)
const storageString = storage.getItem(AUTH_STORAGE_PREFIX + mgr._userStoreKey)

if (storageString) {
const user = User.fromStorageString(storageString)
Expand Down

0 comments on commit 7df5438

Please sign in to comment.