Skip to content

Form digest expiration in SPFx service  #8413

@martinlingstuyl

Description

@martinlingstuyl

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
    104.0.1293.70

  • SPFx version
    1.15.2 (also noted in 1.15.0)

  • Node.js version
    v16.15.1

I'm using a docker dev container to build and serve the SPFx solution.

Describe the bug / error

The problem occurs when using an SPFx service in an SPFx command set extension. The SPFx service consumes the page context and retrieves the Form Digest to be able to call SharePoint endpoints using POST requests. When leaving the page open for more than an hour, and refreshing the page, the form digest will not be retrieved appropriately. You'll get an expired Form Digest. This will lead to 403 errors on post requests.

I've documented the behavior with a sample solution, and gif file here:

https://github.com/martinlingstuyl/spfx-requestdigest-issue

Originally, I filed it with the crew of PnP.js. They are also saying it's an SPFx bug, not a pnp.js bug. See the conversation here:
pnp/pnpjs#2379

Steps to reproduce

  1. Create an SPFx command set extension
  2. Create an SPFx service that consumes the PageContext to retrieve the Form Digest value.
  3. Use the SPfx service in the Command set extension to show or use the form digest.
  4. Wait an hour with the browser open
  5. Refresh the page
  6. The form digest that's being retrieved will be an old digest.

Expected behavior

I'd expect to always get a newed-up form digest after refreshing the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:spfxCategory: SharePoint Framework (not extensions related)area:spfx-in-listsstatus:working-on-itKnown issue / feature being addressed. Will use other "status:*" labels & comments for more detail.type:archive-old-issueIssues which are closed as tool old for active worktype:bug-confirmedConfirmed bug, not working as designed / expected.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions