This repository provides a oauth library which can login hatena using django-allauth.
You can use this as part of the allauth.socialaccount.providers
.
django-allauth-hatena
can install using pip.
$ pip install django-allauth-hatena
It is required django-allauth
, so you should install django-allauth
.
Please add allauth_hatena
to your INSTALLED_APPS
in settings.py
:
INSTALLED_APPS = [
...
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth_hatena',
]
And, set authentication backend for allauth.
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
After that, set socialaccount provider.
# allauth joins multiple scopes with whitespace.
# https://github.com/pennersr/django-allauth/blob/0.35.0/allauth/socialaccount/providers/oauth/views.py#L47
# But, hatena API accept multiple scopes with comma.
# http://developer.hatena.ne.jp/ja/documents/auth/apis/oauth/consumer
# So, you should join with comma when you use multiple scopes.
SOCIALACCOUNT_PROVIDERS = {
'hatena': {
'SCOPE': ['read_public,write_public']
}
}
urls.py:
urlpatterns = [
...
url(r'^accounts/', include('allauth.urls')),
...
]
It is same as normal django-allauth setting.
$ ./manage.py migrate
Now start your server, visit your admin pages (e.g. http://localhost:8000/admin/) and add hatena provider to Social App
.
The package is available as open source under the terms of the MIT License.