Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-openid-auth
Overview
Overview
Details
Activity
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
OpenEdx
django-openid-auth
Commits
0936a94a
Commit
0936a94a
authored
Aug 20, 2008
by
James Henstridge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up util.py a bit.
parent
e75a086e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
51 deletions
+54
-51
django_openidconsumer/util.py
+54
-51
No files found.
django_openidconsumer/util.py
View file @
0936a94a
from
openid.store.interface
import
OpenIDStore
from
openid.association
import
Association
as
OIDAssociation
import
base64
import
md5
import
operator
import
time
from
django.db.models.query
import
Q
from
django.conf
import
settings
import
openid.store
from
openid.association
import
Association
as
OIDAssociation
from
openid.store.interface
import
OpenIDStore
from
openid.store.nonce
import
SKEW
from
openid.yadis
import
xri
import
time
,
base64
,
md5
,
operator
from
models
import
Association
,
Nonce
class
OpenID
:
def
__init__
(
self
,
openid
,
issued
,
attrs
=
None
,
sreg
=
None
):
self
.
openid
=
openid
...
...
@@ -17,99 +21,98 @@ class OpenID:
self
.
attrs
=
attrs
or
{}
self
.
sreg
=
sreg
or
{}
self
.
is_iname
=
(
xri
.
identifierScheme
(
openid
)
==
'XRI'
)
def
__repr__
(
self
):
return
'<OpenID:
%
s>'
%
self
.
openid
def
__str__
(
self
):
return
self
.
openid
class
DjangoOpenIDStore
(
OpenIDStore
):
def
__init__
(
self
):
self
.
max_nonce_age
=
6
*
60
*
60
# Six hours
def
storeAssociation
(
self
,
server_url
,
association
):
assoc
=
Association
(
server_url
=
server_url
,
handle
=
association
.
handle
,
secret
=
base64
.
encodestring
(
association
.
secret
),
issued
=
association
.
issued
,
lifetime
=
association
.
issued
,
assoc_type
=
association
.
assoc_type
)
server_url
=
server_url
,
handle
=
association
.
handle
,
secret
=
base64
.
encodestring
(
association
.
secret
),
issued
=
association
.
issued
,
lifetime
=
association
.
issued
,
assoc_type
=
association
.
assoc_type
)
assoc
.
save
()
def
getAssociation
(
self
,
server_url
,
handle
=
None
):
assocs
=
[]
if
handle
is
not
None
:
assocs
=
Association
.
objects
.
filter
(
server_url
=
server_url
,
handle
=
handle
)
server_url
=
server_url
,
handle
=
handle
)
else
:
assocs
=
Association
.
objects
.
filter
(
server_url
=
server_url
)
if
not
assocs
:
return
None
assocs
=
Association
.
objects
.
filter
(
server_url
=
server_url
)
associations
=
[]
expired
=
[]
for
assoc
in
assocs
:
association
=
OIDAssociation
(
assoc
.
handle
,
base64
.
decodestring
(
assoc
.
secret
),
assoc
.
issued
,
assoc
.
lifetime
,
assoc
.
assoc_type
)
if
association
.
getExpiresIn
()
==
0
:
self
.
removeAssociation
(
server_url
,
assoc
.
handle
)
expired
.
append
(
assoc
)
else
:
associations
.
append
((
association
.
issued
,
association
))
for
assoc
in
expired
:
assoc
.
delete
()
if
not
associations
:
return
None
associations
.
sort
()
return
associations
[
-
1
][
1
]
def
removeAssociation
(
self
,
server_url
,
handle
):
assocs
=
list
(
Association
.
objects
.
filter
(
server_url
=
server_url
,
handle
=
handle
))
server_url
=
server_url
,
handle
=
handle
))
assocs_exist
=
len
(
assocs
)
>
0
for
assoc
in
assocs
:
assoc
.
delete
()
return
assocs_exist
def
useNonce
(
self
,
server_url
,
timestamp
,
salt
):
if
abs
(
timestamp
-
time
.
time
())
>
openid
.
store
.
nonce
.
SKEW
:
if
abs
(
timestamp
-
time
.
time
())
>
SKEW
:
return
False
query
=
[
Q
(
server_url__exact
=
server_url
),
Q
(
timestamp__exact
=
timestamp
),
Q
(
salt__exact
=
salt
),
]
try
:
ononce
=
Nonce
.
objects
.
get
(
reduce
(
operator
.
and_
,
query
))
ononce
=
Nonce
.
objects
.
get
(
server_url__exact
=
server_url
,
timestamp__exact
=
timestamp
,
salt__exact
=
salt
)
except
Nonce
.
DoesNotExist
:
ononce
=
Nonce
(
server_url
=
server_url
,
timestamp
=
timestamp
,
salt
=
salt
);
server_url
=
server_url
,
timestamp
=
timestamp
,
salt
=
salt
)
ononce
.
save
()
return
True
ononce
.
delete
()
return
False
def
cleanupNonce
(
self
):
Nonce
.
objects
.
filter
(
timestamp
<
int
(
time
.
time
())
-
nonce
.
SKEW
)
.
delete
()
def
cleanupNonces
(
self
):
now
=
int
(
time
.
time
())
expired
=
Nonce
.
objects
.
filter
(
Q
(
timestamp__lt
=
now
-
SKEW
)
|
Q
(
timestamp__gt
=
now
+
SKEW
))
count
=
expired
.
count
()
if
count
:
expired
.
delete
()
return
count
def
cleaupAssociations
(
self
):
Association
.
objects
.
extra
(
where
=
[
'issued + lifetimeint<(
%
s)'
%
time
.
time
()])
.
delete
()
now
=
int
(
time
.
time
())
expired
=
Association
.
objects
.
extra
(
where
=
[
'issued + lifetime <
%
d'
%
now
])
count
=
expired
.
count
()
if
count
:
expired
.
delete
()
return
count
def
getAuthKey
(
self
):
# Use first AUTH_KEY_LEN characters of md5 hash of SECRET_KEY
return
md5
.
new
(
settings
.
SECRET_KEY
)
.
hexdigest
()[:
self
.
AUTH_KEY_LEN
]
def
isDumb
(
self
):
return
False
def
from_openid_response
(
openid_response
):
issued
=
int
(
time
.
time
())
...
...
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