Skip to content

A plugin for python-social-auth to authenticate with dataporten

License

Notifications You must be signed in to change notification settings

hmpf/dataporten-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dataporten-auth

Dataporten is an authentication, authorization and API platform for higher and lower education and research in Norway. Dataporten offers authentication of users to applications using OAuth 2.0 and the OpenID Connect.

Dataporten-auth is a client for dataporten that depends on python-social-auth.

Installation

Install with pip or by downloading the source and running setup.py.

Usage

Set up an application at Dataporten

There needs to exist an entry for your site/app at dataporten. Log in to dataporten's dashboard and create an application. The entry needs one or more redirect uris.

You can have several redirect-uris, and you will be needing at least one per plugin used.

The redirect uri is of the form <type>://<domainpath>/<suffix>/, where <type> is one of http or https, <domainpath> is the domain name of your site and an optional path, and the <suffix> is plugin-dependent. See the examples under Plugins.

Set up your site

You'll need to set the client id and client secret generated by Dataporten in the settings of your app/site.

Both the name of the settings and the redirect uris depend on the plugins used. Add at least one of the plugins below.

See python-social-auth's documentation for more.

Django

In your settings.py:

  • Add 'social.apps.django_app.default' to the INSTALLED_APPS.
  • Add one or more of the plugin names above to the start of AUTHENTICATION_BACKENDS. If you're also using user-models à la Django, 'django.contrib.auth.backends.ModelBackend' must be in the same list, following the plugins.
  • Set SOCIAL_AUTH_DATAPORTEN_FEIDE_SSL_PROTOCOL to True to use SSL.
  • SOCIAL_AUTH_LOGIN_REDIRECT_URL, SOCIAL_AUTH_NEW_USER_REDIRECT_URL and SOCIAL_AUTH_REDIRECT_IS_HTTPS will have to be set depending on the needs of your site.
  • If you use the Django admin, you might want to set SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS, for instance to ['username', 'email'].

Also see the settings in src\demosite\settings.py in the source.

Plugins

dataporten.psa.DataportenOAuth2

Plugin name
dataporten.psa.DataportenOAuth2
Settings

Client id: SOCIAL_AUTH_DATAPORTEN_KEY

Client secret: SOCIAL_AUTH_DATAPORTEN_SECRET

Scopes needed
userid and profile, this is the default.
Username generated:
Unique, alphanumeric string. You might want to let users change this generated username. The plugin only cares that a username exists and won't change the username back.
Redirect-uri ends with
/complete/dataporten/
Example redirect uri:
http://127.0.0.1/complete/dataporten/

dataporten.psa.DataportenEmailOAuth2

Plugin name
dataporten.psa.DataportenEmailOAuth2
Settings

Client id: SOCIAL_AUTH_DATAPORTEN_EMAIL_KEY

Client secret: SOCIAL_AUTH_DATAPORTEN_EMAIL_SECRET

Scopes needed
email, this must be explicitly allowed in the dashboard.
Username generated:
From email-address
Redirect-uri ends with
/complete/dataporten_email/
Example redirect uri:
https://supersites.exmaple.net/mysite/complete/dataporten_email/

dataporten.psa.DataportenFeideOAuth2

Plugin name
dataporten.psa.DataportenFeideOAuth2
Settings

Client id: SOCIAL_AUTH_DATAPORTEN_FEIDE_KEY

Client secret: SOCIAL_AUTH_DATAPORTEN_FEIDE_SECRET

Scopes needed
userid-feide, this must be explicitly allowed in the dashboard.
Username generated:
From the Feide attribute eduPersonPrincipalName, which looks like an email address.
Redirect-uri ends with
/complete/dataporten_feide/
Example redirect uri:
https://example.com/cheatsheet/complete/dataporten_feide/

Demo

  1. Get the source code
  2. Install dependencies: pip install -r requirements/demo.txt
  3. Make an application at dataporten
  4. Edit the settings-file to set SOCIAL_AUTH_DATAPORTEN_KEY and SOCIAL_AUTH_DATAPORTEN_SECRET
  5. Set three redirect-uris, all starting with http://127.0.0.1:8000
  6. Run python mange.py runserver
  7. Visit http://127.0.0.1:8000 in a fresh browser. Log out doesn't work (yet), so to reset, delete the file db.sqlite3 and run python mange.py runserver again

Optionally, you can add other python-social-auth plugins as well.

Version:0.1.1

About

A plugin for python-social-auth to authenticate with dataporten

Resources

License

Stars

Watchers

Forks

Packages

No packages published