Problem/Motivation

It should be possible to make requests to JSON:API using Drupal Core's basic authentication.

Proposed resolution

The options argument of the ApiClient class will support an additional optional 'authentication' property. Which allows authentication of type 'basic'. If a username and password is provided, requests to JSON:API will be made using basic authentication.

Remaining tasks

* Implement the necessary changes
** Add authentication option. Thinking something similar to:

{
  authentication: {
    type: 'basic',
    username: 'username',
    password: 'password'
  }
}

** If provided, fetch requests will be made with the following additional header:

Authorization: username:password (base 64 encoded)

* Define necessary types
* Document the current ApiClient class inline.
* Add test coverage.

API changes

* The options object will now include a authentication property.
* Fetch will be updated to set the necessary headers.

Issue fork api_client-3376937

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

brianperry created an issue. See original summary.

brianperry’s picture

pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble

pratik_kamble’s picture

Assigned: pratik_kamble » Unassigned
Status: Active » Needs review
coby.sher’s picture

Status: Needs review » Needs work
pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
Status: Needs work » Active
pratik_kamble’s picture

Assigned: pratik_kamble » Unassigned
Status: Active » Needs review
brianperry’s picture

Status: Needs review » Needs work

Noted a couple of other minor things on the MR, but this is really close.

pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
Status: Needs work » Active
pratik_kamble’s picture

Assigned: pratik_kamble » Unassigned
Status: Active » Needs review
brianperry’s picture

@pratik_kamble and @CobyPear - made one small change to support authentication with customFetch, so keeping this as needs review. If you're ok with that change, the rest of this is good to go from my perspective.

brianperry’s picture

Status: Needs review » Fixed

Merged - marking as fixed. Great work and back and forth on this one @pratik_kamble and @CobyPear

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.