-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
enhancementNew feature or requestNew feature or requesthelp-neededThe maintainer needs help due to time constraint/missing knowledgeThe maintainer needs help due to time constraint/missing knowledgeprovidersstaleDid not receive any activity for 60 daysDid not receive any activity for 60 days
Description
Describe the bug
We're trying to integrate Signicat OpenID with Basic auth and get this message:
{
statusCode: 400,
data: '{"error":"invalid_request","error_description":"Your client is configured to authenticate using CLIENT_SECRET_BASIC"}'
}
This is because client_secret is sent as post data here, even if its null or undefined:
next-auth/src/server/lib/oauth/callback.js
Line 225 in 9dbd372
| const postData = querystring.stringify(params) |
With empty client secret (note the: &client_secret=):
// formData is: grant_type=authorization_code&client_id=client_id&client_secret=&code=code&redirect_uri=uri
{
statusCode: 400,
data: `{"error":"invalid_request","error_description":"Form body malformed! (Body is not a set of key-value pairs separated by '=', delimited by '&' characters)"}`
}Here are some possible solutions:
- Use this querystring library and strip nulls in the query object. https://github.com/sindresorhus/query-string#skipnull
- Change this code to not set the
params.client_secretat all.
if (!params.client_secret) {
if (provider.clientSecretCallback) {
params.client_secret = yield provider.clientSecretCallback(provider.clientSecret);
} else {
params.client_secret = provider.clientSecret;
}
}Steps to reproduce
Use custom oauth2 config:
{
id: "signicat",
name: "Signicat BankID",
type: "oauth",
version: "2.0",
scope: "openid profile signicat.national_id signicat.certificate",
params: { grant_type: "authorization_code" },
accessTokenUrl: `https://${config.signicatHost}/oidc/token`,
requestTokenUrl: `https://${config.signicatHost}/oidc/token`,
authorizationUrl: `https://${config.signicatHost}/oidc/authorize?response_type=code&response_mode=form_post&acr_values=urn:signicat:oidc:method:sbid`,
profileUrl: `https://${config.signicatHost}/oidc/userinfo`,
clientId: config.signicatClientId,
clientSecret: config.signicatClientSecret,
idToken: true,
state: false,
clientSecretCallback: () => null, // Remove client_secret from post data in request
headers: {
Authorization: `Basic ${Buffer.from(config.signicatClientId + ":" + config.signicatClientSecret, "ascii").toString("base64")}`,
}
}Expected behavior
client_secret should be omitted from postData if headers.Authorization.includes("Basic")
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
balazsorban44 and larssbr
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp-neededThe maintainer needs help due to time constraint/missing knowledgeThe maintainer needs help due to time constraint/missing knowledgeprovidersstaleDid not receive any activity for 60 daysDid not receive any activity for 60 days