Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
5c242e46
Unverified
Commit
5c242e46
authored
Sep 06, 2017
by
Robert Knight
Committed by
Sean Hammond
Nov 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the cookie-based authentication service
parent
68e6524b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
133 deletions
+0
-133
auth.js
src/sidebar/auth.js
+0
-54
auth-test.js
src/sidebar/test/auth-test.js
+0
-79
No files found.
src/sidebar/auth.js
deleted
100644 → 0
View file @
68e6524b
'use strict'
;
var
NULL_TOKEN
=
Promise
.
resolve
(
null
);
/**
* Service for fetching and caching access tokens for the Hypothesis API.
*/
// @ngInject
function
auth
(
$http
,
jwtHelper
,
settings
)
{
var
cachedToken
=
NULL_TOKEN
;
/**
* Fetch a new API token for the current logged-in user.
*
* The user is authenticated using their session cookie.
*
* @return {Promise<string>} - A promise for a new JWT token.
*/
function
fetchToken
()
{
var
tokenUrl
=
new
URL
(
'token'
,
settings
.
apiUrl
).
href
;
return
$http
.
get
(
tokenUrl
,
{}).
then
(
function
(
response
)
{
return
response
.
data
;
});
}
/**
* Fetch or return a cached JWT API token for the current user.
*
* @return {Promise<string>} - A promise for a JWT API token for the current
* user.
*/
function
tokenGetter
()
{
return
cachedToken
.
then
(
function
(
token
)
{
if
(
!
token
||
jwtHelper
.
isTokenExpired
(
token
))
{
cachedToken
=
fetchToken
();
return
cachedToken
;
}
else
{
return
token
;
}
});
}
function
clearCache
()
{
cachedToken
=
NULL_TOKEN
;
}
return
{
clearCache
:
clearCache
,
tokenGetter
:
tokenGetter
,
};
}
module
.
exports
=
auth
;
src/sidebar/test/auth-test.js
deleted
100644 → 0
View file @
68e6524b
'use strict'
;
var
auth
=
require
(
'../auth'
);
describe
(
'auth'
,
function
()
{
var
fakeHttp
;
var
fakeJwtHelper
;
var
fakeSettings
;
var
fakeTokens
=
[
'token-one'
,
'token-two'
];
var
fakeTokenIndex
;
beforeEach
(
function
()
{
fakeTokenIndex
=
0
;
fakeHttp
=
{
get
:
sinon
.
spy
(
function
(
url
,
config
)
{
assert
.
equal
(
url
,
'https://test.hypothes.is/api/token'
);
assert
.
deepEqual
(
config
,
{});
var
result
=
{
status
:
200
,
data
:
fakeTokens
[
fakeTokenIndex
]};
++
fakeTokenIndex
;
return
Promise
.
resolve
(
result
);
}),
};
fakeJwtHelper
=
{
isTokenExpired
:
sinon
.
stub
()};
fakeSettings
=
{
apiUrl
:
'https://test.hypothes.is/api/'
,
};
});
function
authFactory
()
{
return
auth
(
fakeHttp
,
fakeJwtHelper
,
fakeSettings
);
}
describe
(
'#tokenGetter'
,
function
()
{
it
(
'should fetch and return a new token'
,
function
()
{
var
auth
=
authFactory
();
return
auth
.
tokenGetter
().
then
(
function
(
token
)
{
assert
.
called
(
fakeHttp
.
get
);
assert
.
equal
(
token
,
fakeTokens
[
0
]);
});
});
it
(
'should cache tokens for future use'
,
function
()
{
var
auth
=
authFactory
();
return
auth
.
tokenGetter
().
then
(
function
()
{
return
auth
.
tokenGetter
();
}).
then
(
function
(
token
)
{
assert
.
calledOnce
(
fakeHttp
.
get
);
assert
.
equal
(
token
,
fakeTokens
[
0
]);
});
});
it
(
'should refresh expired tokens'
,
function
()
{
var
auth
=
authFactory
();
return
auth
.
tokenGetter
().
then
(
function
()
{
fakeJwtHelper
.
isTokenExpired
=
function
()
{
return
true
;
};
return
auth
.
tokenGetter
();
}).
then
(
function
(
token
)
{
assert
.
calledTwice
(
fakeHttp
.
get
);
assert
.
equal
(
token
,
fakeTokens
[
1
]);
});
});
});
describe
(
'#clearCache'
,
function
()
{
it
(
'should remove existing cached tokens'
,
function
()
{
var
auth
=
authFactory
();
return
auth
.
tokenGetter
().
then
(
function
()
{
auth
.
clearCache
();
return
auth
.
tokenGetter
();
}).
then
(
function
(
token
)
{
assert
.
calledTwice
(
fakeHttp
.
get
);
assert
.
equal
(
token
,
fakeTokens
[
1
]);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment