You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package is configured using `django-allauth`'s standard `SOCIALACCOUNT_PROVIDERS` setting. This allows you to set your credentials, select the environment (test or production), and define what data you request from the user.
67
-
68
-
Add the following to your `settings.py`:
53
+
Configure the provider using `django-allauth`'s standard `SOCIALACCOUNT_PROVIDERS` setting in your `settings.py`.
69
54
70
55
```python
71
56
# settings.py
72
57
import os
73
58
74
59
SOCIALACCOUNT_PROVIDERS= {
75
60
'vipps': {
76
-
# Method 1 (Recommended): Configure credentials directly in settings.
77
-
# This is ideal for production and CI/CD environments.
61
+
# Configure credentials using environment variables.
78
62
'APPS': [
79
63
{
80
64
'client_id': os.getenv('VIPPS_CLIENT_ID'),
81
65
'secret': os.getenv('VIPPS_CLIENT_SECRET'),
82
-
'key': ''# Not used by Vipps
66
+
'key': ''
83
67
}
84
68
],
85
69
86
70
# --- General Provider Settings ---
87
-
88
-
# For production, this must be False. For development, set to True
89
-
# to use the Vipps test API ([https://apitest.vipps.no](https://apitest.vipps.no)).
90
-
'TEST_MODE': False,
91
-
92
-
# This tells django-allauth to trust the email address received from Vipps.
71
+
'TEST_MODE': False, # Set to True for development/testing
93
72
'VERIFIED_EMAIL': True,
94
-
95
-
# (Recommended) Enforce that the login fails if Vipps has not
96
-
# verified the user's email address on their end.
97
73
'EMAIL_VERIFIED_REQUIRED': True,
98
-
99
-
# Define the specific user data (scopes) you want to request.
100
74
'SCOPE': [
101
75
'openid',
102
76
'name',
@@ -106,19 +80,17 @@ SOCIALACCOUNT_PROVIDERS = {
106
80
}
107
81
}
108
82
```
109
-
> **Important:** For credentials, choose **one** method. Either use the `APPS` key in `settings.py` (recommended) or create a `SocialApp` in the Django Admin as described in the `django-allauth` documentation. Using both for the same provider will cause an error.
83
+
> **Important:** For credentials, either use the `APPS` key in `settings.py` (recommended) or create a `SocialApp` in the Django Admin. Using both for the same provider will cause an error.
110
84
111
85
### Step 4: Configure on Vipps Developer Portal
112
86
113
-
1. Log in to the [Vipps MobilePay Developer Portal](https://portal.vippsmobilepay.com/).
114
-
2. Navigate to the "Developer" section and get your credentials for a sales unit.
115
-
***Client ID** (goes into `VIPPS_CLIENT_ID` environment variable)
116
-
***Client Secret** (goes into `VIPPS_CLIENT_SECRET` environment variable)
117
-
3. In the **"Redirect URIs"** section, add the URL that Vipps will redirect users back to.
118
-
***Standard Web Flow:**`https://yourdomain.com/accounts/vipps/login/callback/`
119
-
***API/SPA Flow:** This should be the URL of your *frontend* application that handles the final redirect, e.g., `https://my-react-app.com/auth/callback/vipps`
87
+
1. Log in to the [Vipps MobilePay Developer Portal](https://portal.vippsmobilepay.com/).
88
+
2. Get your **Client ID** and **Client Secret**.
89
+
3. Set the **Token endpoint authentication method** to **`client_secret_basic`**.
90
+
4. Add your **Redirect URI** (`https://yourdomain.com/accounts/vipps/login/callback/` for web flows, or your frontend URL for API flows).
91
+
92
+
### Step 5: Run Migrations
120
93
121
-
### Step 5: Run Database Migrations
122
94
```bash
123
95
python manage.py migrate
124
96
```
@@ -127,45 +99,32 @@ python manage.py migrate
127
99
128
100
### For Traditional Django Websites
129
101
130
-
If you are using server-rendered templates, add a Vipps login button with the `provider_login_url` template tag.
131
-
132
-
**In your template (`login.html`):**
102
+
Use the `provider_login_url` template tag.
133
103
```html
134
104
{% load socialaccount %}
135
-
136
-
<h2>Login</h2>
137
105
<ahref="{% provider_login_url 'vipps' %}">Log In with Vipps</a>
138
106
```
139
107
140
108
### For REST APIs (with `dj-rest-auth`)
141
109
142
-
This is the standard flow for Single-Page Applications (React, Vue, etc.).
110
+
When using `dj-rest-auth`, you must use the custom `VippsOAuth2Client` provided by this package to ensure the correct authentication method (`client_secret_basic`) is used.
143
111
144
-
In your project's `urls.py`, create a login view that uses the `VippsOAuth2Adapter`.
112
+
In your project's `urls.py`, create your login view like this:
145
113
146
114
```python
147
115
# your_project/urls.py
148
116
from django.urls import path
149
117
from dj_rest_auth.registration.views import SocialLoginView
150
118
from vipps_auth.views import VippsOAuth2Adapter
119
+
from vipps_auth.client import VippsOAuth2Client # <-- Import the custom client
151
120
152
-
# This view connects dj-rest-auth to our Vipps adapter.
153
-
# No client_class is needed unless you have advanced requirements.
121
+
# This view connects dj-rest-auth to our Vipps adapter
154
122
classVippsLoginAPI(SocialLoginView):
155
123
adapter_class = VippsOAuth2Adapter
156
-
# This MUST match the redirect URI you set in the Vipps Portal for your frontend
124
+
client_class = VippsOAuth2Client # <-- Use the custom client here
0 commit comments