Skip to content

Commit fd9dab3

Browse files
authored
Merge pull request #3 from danpejobo/dev
Dev
2 parents 2295b6f + 8e49476 commit fd9dab3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,40 @@ urlpatterns = [
143143
]
144144
```
145145

146+
#### Step 1.1: If step 1 fails
147+
148+
If for some reason step 1 fails, you can try to use basic auth.
149+
150+
```python
151+
# your_project/urls.py
152+
from django.urls import path
153+
from dj_rest_auth.registration.views import SocialLoginView
154+
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
155+
from vipps_auth.views import VippsOAuth2Adapter
156+
157+
# 1. Create a custom client class that uses HTTP Basic auth when
158+
# exchanging the authorization code. In production Vipps expects the
159+
# `client_id` and `client_secret` to be provided via the
160+
# `Authorization` header, so we enable `basic_auth`.
161+
class VippsBasicAuthClient(OAuth2Client):
162+
def __init__(self, *args, **kwargs):
163+
# Use HTTP Basic auth for the token request
164+
kwargs['basic_auth'] = True
165+
super().__init__(*args, **kwargs)
166+
167+
# This view connects dj-rest-auth to our Vipps adapter
168+
class VippsLoginAPI(SocialLoginView):
169+
adapter_class = VippsOAuth2Adapter
170+
client_class = VippsBasicAuthClient
171+
# This MUST match the redirect URI you set in the Vipps Portal for your frontend
172+
callback_url = "YOUR_FRONTEND_CALLBACK_URL"
173+
174+
urlpatterns = [
175+
# ... your other urls
176+
path("api/v1/auth/vipps/", VippsLoginAPI.as_view(), name="vipps_login_api"),
177+
]
178+
```
179+
146180
#### Step 2: The Frontend Flow
147181

148182
1. **Redirect to Vipps:** Your frontend redirects the user to the Vipps authorization URL. You can get this URL from your provider's `get_authorize_url()` method or construct it manually.
@@ -190,8 +224,8 @@ You can customize the provider's behavior by adding a `VIPPS_AUTH_SETTINGS` dict
190224
191225
VIPPS_AUTH_SETTINGS = {
192226
# The base URL for the Vipps API.
193-
# Default: "[https://apitest.vipps.no](https://apitest.vipps.no)" (for testing)
194-
# For production, use: "[https://api.vipps.no](https://api.vipps.no)"
227+
# Default: "https://apitest.vipps.no" (for testing)
228+
# For production, use: "https://api.vipps.no"
195229
"BASE_URL": "https://api.vipps.no",
196230
197231
# The scopes (permissions) you request from the user.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-allauth-vipps"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A configurable Django Allauth provider for Vipps Login."
55
authors = ["Daniel Persen <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)