Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
43b7fcb1
Commit
43b7fcb1
authored
7 years ago
by
Megan Henning
Browse files
Options
Downloads
Patches
Plain Diff
Add CAS authentication
parent
cc24d125
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/auth/authproviders.py
+55
-1
55 additions, 1 deletion
api/auth/authproviders.py
with
55 additions
and
1 deletion
api/auth/authproviders.py
+
55
−
1
View file @
43b7fcb1
...
...
@@ -4,6 +4,8 @@ import json
import
urllib
import
urlparse
from
xml.etree
import
ElementTree
from
.
import
APIAuthProviderException
,
APIUnknownUserException
,
APIRefreshTokenException
from
..
import
config
,
util
from
..dao
import
dbutil
...
...
@@ -189,6 +191,7 @@ class GoogleOAuthProvider(AuthProvider):
# If the user has no avatar set, mark their provider_avatar as their chosen avatar.
config
.
db
.
users
.
update_one
({
'
_id
'
:
uid
,
'
avatar
'
:
{
'
$exists
'
:
False
}},
{
'
$set
'
:{
'
avatar
'
:
provider_avatar
,
'
modified
'
:
timestamp
}})
class
WechatOAuthProvider
(
AuthProvider
):
def
__init__
(
self
):
...
...
@@ -278,6 +281,56 @@ class WechatOAuthProvider(AuthProvider):
pass
class
CASAuthProvider
(
AuthProvider
):
def
__init__
(
self
):
super
(
CASAuthProvider
,
self
).
__init__
(
'
cas
'
)
def
validate_code
(
self
,
code
,
**
kwargs
):
uid
=
self
.
validate_user
(
code
)
return
{
'
access_token
'
:
code
,
'
uid
'
:
uid
,
'
auth_type
'
:
self
.
auth_type
,
'
expires
'
:
datetime
.
datetime
.
utcnow
()
+
datetime
.
timedelta
(
days
=
14
)
}
def
validate_user
(
self
,
token
):
config
.
log
.
warning
(
'
the config is {}
\n\n
'
.
format
(
self
.
config
))
r
=
requests
.
get
(
self
.
config
[
'
verify_endpoint
'
],
params
=
{
'
ticket
'
:
token
,
'
service
'
:
self
.
config
[
'
service_url
'
]})
if
not
r
.
ok
:
raise
APIAuthProviderException
(
'
User token not valid
'
)
username
=
self
.
_parse_xml_response
(
r
.
content
)
uid
=
username
+
'
@
'
+
self
.
config
[
'
namespace
'
]
self
.
ensure_user_exists
(
uid
)
self
.
set_user_gravatar
(
uid
,
uid
)
return
uid
def
_parse_xml_response
(
self
,
response
):
# parse xml
tree
=
ElementTree
.
fromstring
(
response
)
# check to see if xml response labeled request as success
if
tree
[
0
].
tag
.
endswith
(
'
authenticationSuccess
'
):
# get username from response
namespace
=
tree
.
tag
[
0
:
tree
.
tag
.
index
(
'
}
'
)
+
1
]
username
=
tree
[
0
].
find
(
'
.//
'
+
namespace
+
'
user
'
).
text
else
:
raise
APIAuthProviderException
(
'
Auth provider ticket verification unsuccessful.
'
)
if
not
username
:
raise
APIAuthProviderException
(
'
Auth provider did not provide username
'
)
return
username
class
APIKeyAuthProvider
(
AuthProvider
):
"""
Uses an API key for authentication.
...
...
@@ -339,5 +392,6 @@ AuthProviders = {
'
google
'
:
GoogleOAuthProvider
,
'
ldap
'
:
JWTAuthProvider
,
'
wechat
'
:
WechatOAuthProvider
,
'
api-key
'
:
APIKeyAuthProvider
'
api-key
'
:
APIKeyAuthProvider
,
'
cas
'
:
CASAuthProvider
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment