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
0f66a5de
Commit
0f66a5de
authored
Oct 03, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tighten up the identity and auth interaction
Handle errors, ready notification, cancellations and cleanups.
parent
4fd12f8b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
42 deletions
+51
-42
auth-controller.coffee
h/static/scripts/auth/auth-controller.coffee
+5
-4
auth.coffee
h/static/scripts/auth/auth.coffee
+21
-16
controllers.coffee
h/static/scripts/controllers.coffee
+0
-1
identity.coffee
h/static/scripts/identity.coffee
+25
-21
No files found.
h/static/scripts/auth/auth-controller.coffee
View file @
0f66a5de
...
...
@@ -5,7 +5,7 @@ class AuthController
success
=
(
data
)
->
if
$scope
.
tab
is
'forgot'
then
$scope
.
tab
=
'activate'
if
data
.
userid
then
$scope
.
$emit
'
session'
,
data
if
data
.
userid
then
$scope
.
$emit
'
auth'
,
null
,
data
$scope
.
model
=
null
$scope
.
form
?
.
$setPristine
()
...
...
@@ -27,9 +27,10 @@ class AuthController
$scope
.
model
=
null
$scope
.
tab
=
'login'
$scope
.
$on
'$destroy'
,
->
if
timeout
$timeout
.
cancel
timeout
$scope
.
$on
'auth'
,
do
->
preventCancel
=
$scope
.
$on
'$destroy'
,
->
if
timeout
then
$timeout
.
cancel
timeout
$scope
.
$emit
'auth'
,
'cancel'
$scope
.
$watchCollection
'model'
,
(
value
)
->
# Reset the auth forms after five minutes of inactivity
...
...
h/static/scripts/auth/auth.coffee
View file @
0f66a5de
...
...
@@ -11,31 +11,36 @@ configure = [
# Use the Pyramid XSRF header name
$httpProvider
.
defaults
.
xsrfHeaderName
=
'X-CSRF-Token'
identityProvider
.
checkAuthorization
=
[
'session'
,
(
session
)
->
session
.
load
().
$promise
.
then
(
data
)
->
certificate
:
data
.
csrf
userid
:
data
.
userid
identityProvider
.
checkAuthentication
=
[
'$q'
,
'session'
,
(
$q
,
session
)
->
(
authCheck
=
$q
.
defer
())
.
promise
.
then
do
->
session
.
load
().
$promise
.
then
(
data
)
->
authCheck
.
resolve
certificate
:
data
.
csrf
userid
:
data
.
userid
]
identityProvider
.
forgetAuth
oriz
ation
=
[
identityProvider
.
forgetAuth
entic
ation
=
[
'session'
,
(
session
)
->
session
.
logout
({}).
$promise
]
identityProvider
.
requestAuth
oriz
ation
=
[
identityProvider
.
requestAuth
entic
ation
=
[
'$q'
,
'$rootScope'
,
(
$q
,
$rootScope
)
->
deferred
=
$q
.
defer
()
$rootScope
.
$on
'session'
,
(
event
,
data
)
->
deferred
.
resolve
certificate
:
data
.
csrf
userid
:
data
.
userid
deferred
.
promise
if
authCheck
then
authCheck
.
reject
()
(
authCheck
=
$q
.
defer
())
.
promise
.
finally
do
->
$rootScope
.
$on
'auth'
,
(
event
,
err
,
data
)
->
if
err
authCheck
.
reject
(
err
)
else
authCheck
.
resolve
certificate
:
data
.
csrf
userid
:
data
.
userid
]
]
...
...
h/static/scripts/controllers.coffee
View file @
0f66a5de
...
...
@@ -200,7 +200,6 @@ class AppController
oncancel
=
->
loggedInuser
=
null
reset
()
onlogin
=
(
assertion
)
->
# Configure the Auth plugin with the issued assertion as refresh token.
...
...
h/static/scripts/identity.coffee
View file @
0f66a5de
...
...
@@ -2,17 +2,20 @@
# @ngdoc provider
# @name identityProvider
# @property {function} checkAuthorization A function to check for a current
# authorization grant. It is expected to return the promise of a grant.
# @property {function} checkAuthentication A function to check for an
# authenticated user. It is expected to return the promise of an authorization
# grant if the user has authorized signing in to the requesting application.
# The function arguments are injected.
#
# @property {function} forgetAuthorization A function to forget the current
# authorization grant. It is expected to return the promise of a grant. If
# the user is successfully logged out the grant should be null or invalid.
# @property {function} forgetAuthentication A function to forget the current
# authentication. The return value, if any, will be resolved as a promise
# before the identity service fires logout callbacks. The identity provider
# should ensure any sessions are cleared. The function arguments are injected.
#
# @property {function} requestAuth
oriz
ation A function to request that the
# the
client begin authenticated the current user. It is expected to return the
#
promise of an authorization grant once the user has authenticated and
#
authorized signing in to the requesting application
.
# @property {function} requestAuth
entic
ation A function to request that the
# the
user begin authenticating. It is expected to return the promise of an
#
authorization grant once the user has authenticated and authorized signing
#
in to the requesting application. The function arguments are injected
.
#
# @description
# The `identityProvider` is used to configure functions that fulfill
...
...
@@ -28,16 +31,16 @@
# ``userid`` and ``certificate``.
###
identityProvider = ->
checkAuth
oriz
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#checkAuth
oriz
ation.'
checkAuth
entic
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#checkAuth
entic
ation.'
]
forgetAuth
oriz
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#forgetAuth
oriz
ation.'
forgetAuth
entic
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#forgetAuth
entic
ation.'
]
requestAuth
oriz
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#requestAuth
oriz
ation.'
requestAuth
entic
ation: ['$q', ($q) ->
$q.reject 'Not implemented idenityProvider#requestAuth
entic
ation.'
]
###
*
...
...
@@ -59,6 +62,7 @@ identityProvider = ->
onlogin = null
onlogout = null
onmatch = null
onready = null
invokeCallbacks = (grant={}) ->
{userid, certificate} = grant
...
...
@@ -97,8 +101,8 @@ identityProvider = ->
# https://developer.mozilla.org/en-US/docs/Web/API/navigator.id.logout
###
logout: ->
result = $injector.invoke(provider.forgetAuth
oriz
ation, provider)
$q.when(result).finally(
-> onlogout?()
)
result = $injector.invoke(provider.forgetAuth
entic
ation, provider)
$q.when(result).finally(
invokeCallbacks
)
###
*
# @ngdoc method
...
...
@@ -108,7 +112,7 @@ identityProvider = ->
###
request: (options={}) ->
{oncancel} = options
result = $injector.invoke(provider.requestAuth
oriz
ation, provider)
result = $injector.invoke(provider.requestAuth
entic
ation, provider)
$q.when(result).then(invokeCallbacks, oncancel)
###
*
...
...
@@ -118,9 +122,9 @@ identityProvider = ->
# https://developer.mozilla.org/en-US/docs/Web/API/navigator.id.watch
###
watch
:
(
options
)
->
{
loggedInUser
,
onlogin
,
onlogout
,
onmatch
}
=
options
result
=
$injector
.
invoke
(
provider
.
checkAuth
oriz
ation
,
provider
)
result
.
then
(
invokeCallbacks
)
{
loggedInUser
,
onlogin
,
onlogout
,
onmatch
,
onready
}
=
options
result
=
$injector
.
invoke
(
provider
.
checkAuth
entic
ation
,
provider
)
$q
.
when
(
result
).
then
(
invokeCallbacks
,
null
,
onready
)
]
...
...
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