Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApiAuth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruce Flynn
ApiAuth
Commits
98f27523
Commit
98f27523
authored
8 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
tweak, rinse, repeat
parent
dc3d0d48
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+13
-0
13 additions, 0 deletions
README.md
apiauth/app.py
+16
-5
16 additions, 5 deletions
apiauth/app.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
30 additions
and
6 deletions
README.md
0 → 100644
+
13
−
0
View file @
98f27523
# API Authentication Example App
## Getting Started
I highly recommend using either
[
Conda
](
http://conda.pydata.org/miniconda.html
)
or
[
VirtualEnv
](
https://virtualenv.pypa.io/en/stable/
)
.
1.
Install the app and its dependencies:
```
pip install -e .
pserve --reload development.ini
```
2.
Open your browser and navigate to http://localhost:6543/
3.
Register
This diff is collapsed.
Click to expand it.
apiauth/app.py
+
16
−
5
View file @
98f27523
from
pyramid.config
import
Configurator
from
pyramid.security
import
Allow
,
Everyone
,
Authenticated
from
pyramid.authorization
import
ACLAuthorizationPolicy
from
pyramid.authentication
import
RemoteUserAuthenticationPolicy
class
RootFactory
(
object
):
__acl__
=
[
# any member of the Science Team will have ApiAccess permission
(
Allow
,
'
group:scienceteam
'
,
'
ApiAccess
'
)
]
...
...
@@ -14,17 +14,28 @@ class RootFactory(object):
class
ScienceTeamAuthPolicy
(
object
):
"""
Identifies users as members of the ScienceTeam. In theory this infomation
would be obtained from a user database or something.
"""
# any user in this list will be a member of the science team
SCIENCETEAM
=
[
'
brucef
'
]
# IAuthenticationPolicy
# we don't need to remember or forget
remember
=
lambda
*
a
:
[]
forget
=
lambda
*
a
:
[]
def
_noop
(
self
,
*
args
):
return
[]
remember
=
_noop
forget
=
_noop
# IAuthenticationPolicy
def
unauthenticated_userid
(
self
,
request
):
"""
Return userid if they are authenticated.
"""
apikey
=
request
.
params
.
get
(
'
apikey
'
)
userdb
=
request
.
registry
.
settings
[
'
userdb
'
]
# check registered user db to see if apikey matches
for
user
,
data
in
userdb
.
items
():
if
data
[
'
apikey
'
]
==
apikey
:
return
user
...
...
@@ -46,7 +57,7 @@ class ScienceTeamAuthPolicy(object):
def
main
(
global_config
,
**
settings
):
"""
This function returns a Pyramid WSGI application.
"""
# in memory user database
# in memory user database
, populated by registraion page
settings
[
'
userdb
'
]
=
{}
config
=
Configurator
(
root_factory
=
RootFactory
,
settings
=
settings
)
...
...
@@ -61,4 +72,4 @@ def main(global_config, **settings):
config
.
scan
()
return
config
.
make_wsgi_app
()
\ No newline at end of file
return
config
.
make_wsgi_app
()
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
98f27523
from
setuptools
import
setup
,
find_packages
requires
=
[
'
pyramid
'
,
'
pyramid
==1.7
'
,
'
pyramid_chameleon
'
,
'
pyramid_debugtoolbar
'
,
'
waitress
'
,
...
...
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