Friday, May 24, 2024

basic cheat sheet for SharePoint Framework (SPFx) development, covering essential commands and steps for setting up, developing, and managing SPFx projects

Here's a basic cheat sheet for SharePoint Framework (SPFx) development, covering essential commands and steps for setting up, developing, and managing SPFx projects:

Prerequisites

  1. Node.js (LTS version recommended)
  2. Yeoman and Gulp:
    bash
    npm install -g yo gulp
  3. Yeoman SharePoint Generator:
    bash
    npm install -g @microsoft/generator-sharepoint

Setting Up a New SPFx Project

  1. Create a new directory and navigate into it:
    bash
    mkdir my-spfx-webpart cd my-spfx-webpart
  2. Generate a new SPFx solution:
    bash
    yo @microsoft/sharepoint
    Follow the prompts to configure your project:
    • SharePoint Online only (latest)
    • WebPart (or Extension)
    • JavaScript framework (React, No framework, etc.)

Development Commands

  1. Serve the project locally:

    bash
    gulp serve

    This opens a local workbench in your browser where you can test your web parts.

  2. Build the project:

    bash
    gulp build

    Compiles the project and prepares it for packaging or deployment.

  3. Bundle the project:

    bash
    gulp bundle --ship

    Creates a production-ready bundle of your project.

  4. Package the solution:

    bash
    gulp package-solution --ship

    Generates the .sppkg file in the sharepoint/solution directory, which can be uploaded to the App Catalog in SharePoint.

Additional Useful Commands

  1. Clean the build directory:

    bash
    gulp clean

    Removes old build files.

  2. Trust Dev Cert (needed for local HTTPS):

    bash
    gulp trust-dev-cert
  3. Untrust Dev Cert:

    bash
    gulp untrust-dev-cert
  4. Upgrade SPFx project (using the Office 365 CLI):

    bash
    npm install -g @pnp/cli-microsoft365 m365 spfx project upgrade --output md > upgrade-report.md

File Structure Overview

  • src: Contains all source code for your web parts or extensions.
    • webparts: Contains web part specific files.
    • extensions: Contains extension specific files.
  • config: Contains configuration files for the build process.
  • sharepoint: Contains assets and deployment-related files.
    • assets: Contains static assets for the project.
    • solution: Contains the packaged solution file.

Useful Links

Tuesday, November 7, 2023

SharePoint client authentication

 SharePoint client authentication is the process by which external applications or services are authenticated when accessing resources within a SharePoint environment. SharePoint supports various authentication methods to ensure that only authorized clients can interact with SharePoint sites, lists, libraries, and other resources. Here are some common authentication methods for SharePoint clients:


1. **SharePoint Online:** If you are using SharePoint Online as part of Microsoft 365, there are several authentication methods available:


    a. **OAuth:** OAuth (Open Authorization) is the recommended authentication method for SharePoint Online. It allows external applications to request access to SharePoint resources on behalf of a user without exposing the user's credentials. OAuth 2.0 is widely used for this purpose.


    b. **App-Only:** This method is suitable for applications that need to access SharePoint resources without user interaction. It involves registering an app in Azure Active Directory (Azure AD) and granting it the necessary permissions to access SharePoint resources.


    c. **SAML-Based Authentication:** You can use Security Assertion Markup Language (SAML) to enable single sign-on (SSO) for your SharePoint Online applications. This method allows users to authenticate once and access SharePoint without additional logins.


2. **SharePoint on-premises:** For SharePoint deployments hosted on your own servers, there are several authentication methods, including:


    a. **Windows Authentication:** Windows authentication is commonly used in on-premises SharePoint environments. It relies on the user's Windows credentials to grant access to SharePoint resources.


    b. **Forms-Based Authentication:** Forms-based authentication allows custom authentication providers and can be used in scenarios where Windows authentication is not suitable.


    c. **SAML-Based Authentication:** SAML can also be used in on-premises SharePoint deployments to enable single sign-on.


3. **Hybrid Deployments:** Some organizations use a combination of SharePoint Online and on-premises SharePoint. In such cases, hybrid authentication methods may be required to bridge the gap between cloud and on-premises environments.


4. **API Tokens:** In certain scenarios, SharePoint clients might use API tokens or API keys to authenticate and access SharePoint resources. These tokens are issued by SharePoint and can be used in API requests for authorization.


The specific authentication method you choose depends on your SharePoint deployment type (online or on-premises), the client applications you are developing, and your security requirements. Regardless of the method, it's essential to secure your SharePoint environment and ensure that only authorized clients have access to your resources. Properly configuring authentication and authorization settings is crucial for SharePoint security.