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