Commit ccbb67be authored by Randall Leeds's avatar Randall Leeds

Fetch api tokens in a separate request

Instead of sending a token with the application view (which is really
more of a session state view), fetch it separately using the tokenUrl
option of the Auth plugin. Account for the case where known personas
could change in the future without invalidating the current persona
and reset the Auth plugin whenever the persona in use changes. Use the
persona parameter to the token endpoint to get the appropriate token.
parent 5edd74ee
...@@ -28,40 +28,38 @@ class App ...@@ -28,40 +28,38 @@ class App
{plugins, host, providers} = annotator {plugins, host, providers} = annotator
$scope.$watch 'auth.personas', (newValue, oldValue) => $scope.$watch 'auth.personas', (newValue, oldValue) =>
unless newValue?.length if newValue?.length
authentication.persona = null unless $scope.auth.persona and $scope.auth.persona in newValue
authentication.token = null $scope.auth.persona = newValue[0]
else
$scope.auth.persona = null
$scope.$watch 'auth.persona', (newValue, oldValue) => $scope.$watch 'auth.persona', (newValue, oldValue) =>
if oldValue? and not newValue? $scope.sheet.collapsed = true
if annotator.discardDrafts()
# TODO: better knowledge of routes unless annotator.discardDrafts()
authentication.$logout => $scope.$broadcast '$reset' $scope.auth.persona = oldValue
else return
$scope.auth.persona = oldValue
else if newValue?
$scope.sheet.collapsed = true
$scope.$watch 'auth.token', (newValue, oldValue) =>
if plugins.Auth? if plugins.Auth?
plugins.Auth.token = newValue plugins.Auth.token = null
plugins.Auth.updateHeaders() plugins.Auth.updateHeaders()
delete plugins.Auth
if plugins.Permissions?
plugins.Permissions.setUser(null)
# XXX: Temporary workaround until Annotator v2.0 or v1.2.10
plugins.Permissions.options.permissions =
read: []
update: []
delete: []
admin: []
plugins.Permissions.setUser(null)
# XXX: Temporary workaround until the fixed version upstream annotator is consumed
# The problem is that the permissions plugin, when setting the annotation.permissions property
# does not copy its options.permissions object, so modifying the annotation.permissions object
# modifes the plugin's options.permissions object too. After that this can be removed.
plugins.Permissions.options.permissions =
read: []
update: []
delete: []
admin: []
if newValue? if newValue?
if not plugins.Auth? acct = "acct:#{newValue.username}@#{newValue.provider}"
annotator.addPlugin 'Auth', token: newValue annotator.addPlugin 'Auth',
else tokenUrl: "/api/token?persona=#{acct}"
plugins.Auth.setToken(newValue)
plugins.Auth.withToken (token) => plugins.Auth.withToken (token) =>
plugins.Permissions._setAuthFromToken token plugins.Permissions._setAuthFromToken token
...@@ -75,8 +73,9 @@ class App ...@@ -75,8 +73,9 @@ class App
annotator.setTool 'highlight' annotator.setTool 'highlight'
else else
$scope.reloadAnnotations() $scope.reloadAnnotations()
else else if oldValue?
delete plugins.Auth authentication.$logout => $scope.$broadcast '$reset'
if annotator.tool isnt 'comment' if annotator.tool isnt 'comment'
annotator.setTool 'comment' annotator.setTool 'comment'
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment