Skip to content

client_secret being passed in post data in Basic auth #950

@carlbarrdahl

Description

@carlbarrdahl

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:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp-neededThe maintainer needs help due to time constraint/missing knowledgeprovidersstaleDid not receive any activity for 60 days

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions