npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-msgraph

v1.3.0

Published

This repository contains custom Node-RED nodes to interact with the Microsoft Graph API. These nodes handle authentication, token management, and allow querying the Microsoft Graph API using Node-RED.

Downloads

90

Readme

Node-RED MS Graph API Nodes

This repository contains custom Node-RED nodes to interact with the Microsoft Graph API. These nodes handle authentication, token management, and allow querying the Microsoft Graph API using Node-RED.

Nodes

  • msgraph-config: Configuration node to store MS Graph API credentials and manage authentication.
  • msgraph-login: Generates an authentication URL to log in to the Microsoft Graph API.
  • msgraph-login-response: Handles the OAuth2 callback and exchanges an authorization code for access tokens.
  • msgraph-query: Makes authenticated requests to the Microsoft Graph API.

Installation

1. Install via npm

You can install these nodes directly using npm. Run the following command in your Node-RED user directory, typically ~/.node-red:

cd ~/.node-red
npm install node-red-contrib-msgraph

2. Install via Node-RED Palette Manager

  1. Open your Node-RED Editor.
  2. Go to the menu (☰) in the top right corner.
  3. Select "Manage palette."
  4. Go to the "Install" tab.
  5. Search for node-red-contrib-msgraph.
  6. Click on the install button next to the node-red-contrib-msgraph package.

Node Descriptions

msgraph-config

This node stores the necessary credentials to authenticate with the Microsoft Graph API and manages token caching.

Properties:

  • clientId: The application (client) ID from your Azure AD app registration.
  • clientSecret: The application secret from your Azure AD app registration.
  • tenantId: The directory (tenant) ID of your Azure AD.
  • redirectUri: The redirect URI configured in your Azure AD app registration.

msgraph-login

This node generates an authentication URL that redirects users to the Microsoft login page.

Usage:

  1. Add the msgraph-login node to your flow.
  2. Connect an inject node to trigger it.
  3. Obtain the authentication URL from the output and visit it to log in to Microsoft Graph.

Example:

[
  {
    "id": "inject1",
    "type": "inject",
    "name": "Start Login",
    "props": [],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": "0.1",
    "wires": [["msgraph-login1"]]
  },
  {
    "id": "msgraph-login1",
    "type": "msgraph-login",
    "msGraphConfig": "msgraph-config1",
    "name": "",
    "wires": [["debug1"]]
  },
  {
    "id": "debug1",
    "type": "debug",
    "name": "Auth URL",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false
  }
]

msgraph-login-response

This node handles the OAuth2 callback, exchanges the authorization code for access tokens, and stores these tokens.

Usage:

  1. Configure an HTTP input node to handle the redirect URI. It will be a GET request with your specified URI.
  2. Connect it to the msgraph-login-response node.

Example:

[
  {
    "id": "http-in1",
    "type": "http in",
    "url": "/auth/callback",
    "method": "get",
    "name": "",
    "wires": [["msgraph-login-response1"]]
  },
  {
    "id": "msgraph-login-response1",
    "type": "msgraph-login-response",
    "msGraphConfig": "msgraph-config1",
    "name": "",
    "wires": [["debug2"]]
  },
  {
    "id": "debug2",
    "type": "debug",
    "name": "Login Response",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false
  }
]

msgraph-query

This node makes authenticated requests to the Microsoft Graph API using the access token.

Usage:

  1. Add the msgraph-query node to your flow.
  2. Configure the query parameters in msg.payload.

Example:

[
  {
    "id": "inject2",
    "type": "inject",
    "name": "Start Query",
    "props": [],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": "0.1",
    "wires": [["function2"]]
  },
  {
    "id": "function2",
    "type": "function",
    "name": "Set Query Params",
    "func": "msg.payload = {\n    endpoint: '/me', // Set the endpoint for the query\n    method: 'GET' // HTTP method\n};\nreturn msg;",
    "wires": [["msgraph-query1"]]
  },
  {
    "id": "msgraph-query1",
    "type": "msgraph-query",
    "msGraphConfig": "msgraph-config1",
    "name": "",
    "wires": [["debug3"]]
  },
  {
    "id": "debug3",
    "type": "debug",
    "name": "Query Result",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false
  }
]

Error Handling: This node provides detailed error messages with msg.payload and sets msg.statusCode to indicate HTTP status codes.

  • 401: Unauthorized if access token is not available.
  • 504: Gateway Timeout if no response is received.
  • 500: Internal Server Error for other exceptions.

Development

Prerequisites

  • Node.js
  • Node-RED

Running Locally

  1. Clone the repository.
  2. Install dependencies.
  3. Start Node-RED and test the nodes by creating flows.
git clone <repository-url>
cd node-red-contrib-msgraph
npm install
node-red

Contributing

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes.
  4. Submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements