OAuth 2 / OpenID Connect Client for Web API runtimes

Overview

OAuth 2 / OpenID Connect Client for Web APIs runtime

This is a collection of bits and pieces upon which a more streamlined Client module may be written.

In Scope & Implemented

  • Authorization Server Metadata discovery
  • OpenID Connect 1.0 and OAuth 2.0 Authorization Code Flow
  • PKCE
  • Refresh Token Grant
  • Device Authorization Grant
  • Client Credentials Grant
  • Demonstrating Proof-of-Possession at the Application Layer (DPoP)
  • Token Introspection
  • JWT Token Introspection
  • Token Revocation
  • JWT Secured Authorization Response Mode (JARM)
  • Confidential and Public Client
  • JWT-Secured Authorization Request (JAR)
  • Pushed Authorization Requests (PAR)
  • UserInfo Requests (Bearer and DPoP)
  • JWT UserInfo Responses
  • Protected Resource Requests (Bearer and DPoP)
  • Authorization Server Issuer Identification

Dependencies: 0

Documentation

Examples

example ESM import

import * as oauth2 from '@panva/oauth4webapi'

example Deno import

import * as oauth2 from 'https://deno.land/x/doauth/src/index.ts'

Runtime requirements

The supported javascript runtimes include ones that

Other than browsers the supported runtimes are

  • Deno (v1.20.1 and newer)
  • Cloudflare Workers
  • Vercel Edge Functions
  • Next.js Middlewares
  • Electron (renderer process)

Pending runtime support

Out of scope

  • CommonJS
  • OAuth 2.0 & OpenID Connect Implicit Flows
  • OAuth 2.0 Resource Owner Password Credentials
  • OpenID Connect Hybrid Flows
  • MTLS (because fetch does not support client certificates)
  • JWS HMAC Signed Responses
  • JWE Encrypted Responses
  • JWE Key Encryption with RSAES-PKCS1-v1_5
  • JWE Key Wrapping with AES Key Wrap
  • JWE Key Encryption with AES GCM
  • JWE Key Encryption with PBES2
  • JWE Direct Encryption with a Shared Symmetric Key
Comments
  • Cross Origin Request Blocked: User Agent on discovery fetch

    Cross Origin Request Blocked: User Agent on discovery fetch

    What happened?

    I'm getting CORS errors with discoveryRequest and GitLab. Some minimal reproducable code:

    const issuer = new URL("https://gitlab.com/.well-known/openid-configuration");
    const as = await oauth.discoveryRequest(issuer);
    

    I'm not a web developer, but I'm quite sure it is related to the library overriding the user-agent in prepareHeaders. Some minimal reproducable code without using the library:

    const issuer = new URL("https://gitlab.com/.well-known/openid-configuration");
    
    const headers = new Headers();
    headers.set("user-agent", "oauth4webapi/v1.0.3"); // Works without this line
    headers.set("accept", "application/json");
    
    fetch(issuer.href, { headers, method: "GET", redirect: "manual" })
      .then((response) => response.json())
      .then((data) => console.log(data));
    

    Should the user-agent really be the library? Usually it is the browser, isn't it?

    Version

    v1.0.3

    Runtime

    Browser

    Runtime Details

    Linux, Firefox & Chrome

    Code to reproduce

    const issuer = new URL("https://gitlab.com/.well-known/openid-configuration");
    const as = await oauth.discoveryRequest(issuer);
    

    Required

    • [X] I have searched the issues tracker and discussions for similar topics and couldn't find anything related.
    • [X] I agree to follow this project's Code of Conduct
    opened by Leon0402 8
  • GitHub OAuth responds with 200 on error

    GitHub OAuth responds with 200 on error

    What happened?

    The line here assumes the error of the response has been handled, but the GitHub authorization response returns a 200 with the error property set in JSON. I believe the correct behavior would be to check if error has been set before checking for access_token and return early.

    Version

    1.0.4

    Runtime

    Cloudflare Workers

    Runtime Details

    N/A

    Code to reproduce

      const response = await oauth2.authorizationCodeGrantRequest(
        as,
        client,
        parameters,
        getRedirectUri(),
        oauth2.generateRandomCodeVerifier()
      );
    
      const result = await oauth2.processAuthorizationCodeOAuth2Response(
        as,
        client,
        response
      );
    
    

    Required

    • [X] I have searched the issues tracker and discussions for similar topics and couldn't find anything related.
    • [X] I agree to follow this project's Code of Conduct
    wontfix 
    opened by blakeembrey 7
  • build(deps-dev): bump workerd from 1.20220926.3 to 1.20221111.4

    build(deps-dev): bump workerd from 1.20220926.3 to 1.20221111.4

    Bumps workerd from 1.20220926.3 to 1.20221111.4.

    Release notes

    Sourced from workerd's releases.

    v1.20221108.0

    What's Changed

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 3
  • Allow empty strings in response

    Allow empty strings in response

    GitHub allows for an empty scope string to request public user information: https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes. Alternatively I could add an ignoreScopes option like the other "ignore" flags but that looks like it'll get overwhelming quickly. Happy to modify it as needed.

    Edit: Alternatively it could also be a skip symbol. Let me know if either of these work for you and I can update the PR.

    opened by blakeembrey 3
  • allow expires_in string type

    allow expires_in string type

    naver provider's response is below.

    {
      access_token: '...',
      refresh_token: '...',
      token_type: 'bearer',
      expires_in: '3600'
    }
    

    expires_in is a string type. so I modified a if condition that allow string type.

    opened by csbok 1
  • Your worker called response.clone(), but did not read the body of both clones

    Your worker called response.clone(), but did not read the body of both clones

    What happened?

    Running this

    const issuer = new URL("...");
    const as = await oauth2
      .discoveryRequest(issuer)
      .then((response) => oauth2.processDiscoveryResponse(issuer, response))
    

    causes Cloudflare Workers to issue the following warning:

    Your worker called response.clone(), but did not read the body of both clones. This is wasteful, as it forces the system to buffer the entire response body in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the response headers and metadata (e.g. in order to be able to modify them), use new Response(response.body, response) instead.

    Version

    v2.0.1

    Runtime

    Cloudflare Workers

    Runtime Details

    Wrangler compatibility_date = "2022-11-25"

    Code to reproduce

    export default {
    	async fetch(
    		request: Request,
    		env: Env,
    		ctx: ExecutionContext
    	): Promise<Response> {
    		const url = new URL(request.url);
    
    		if (url.pathname === "/") {
    			const issuer = new URL("...");
    			const as = await oauth2
    				.discoveryRequest(issuer)
    				.then((response) => oauth2.processDiscoveryResponse(issuer, response))
    
    			console.log(as);
    
    			return new Response(null, { headers, status: 302 });
    		} else {
    			return new Response(null, { status: 404 });
    		}
    	},
    };
    

    Required

    • [X] I have searched the issues tracker and discussions for similar topics and couldn't find anything related.
    • [X] I agree to follow this project's Code of Conduct
    opened by Fabb111 1
  • build(deps-dev): bump typedoc-plugin-markdown from 3.11.14 to 3.12.0

    build(deps-dev): bump typedoc-plugin-markdown from 3.11.14 to 3.12.0

    Bumps typedoc-plugin-markdown from 3.11.14 to 3.12.0.

    Release notes

    Sourced from typedoc-plugin-markdown's releases.

    [email protected]

    3.12.0 (2022-04-09)

    Bug Fixes

    Features

    Changelog

    Sourced from typedoc-plugin-markdown's changelog.

    3.12.0 (2022-04-09)

    Bug Fixes

    Features

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Node.js support

    Node.js support

    Fetch API and Web Crypto API globals are not yet available in some Node.js versions but they can be enabled via node's CLI.

    • Node.js ^16.15.0 requires the --experimental-global-webcrypto and --experimental-fetch command-line flags.
    • Node.js ^18.0.0 requires the --experimental-global-webcrypto command-line flag.
    • Node.js >=19.0.0 requires no command-line flags 🎉.

    These may be provided to the node executable as command-line flags

    node --experimental-global-webcrypto --experimental-fetch ...
    

    or via the NODE_OPTIONS environment variables, e.g.

    export NODE_OPTIONS='--experimental-global-webcrypto --experimental-fetch'
    
    opened by panva 0
Releases(v2.0.6)
  • v2.0.6(Dec 16, 2022)

  • v2.0.5(Dec 11, 2022)

  • v2.0.4(Nov 27, 2022)

  • v2.0.3(Nov 25, 2022)

  • v2.0.1(Nov 21, 2022)

  • v2.0.0(Nov 20, 2022)

    ⚠ BREAKING CHANGES

    • Use the TLS server validation in processAuthorizationCodeOpenIDResponse to validate the issuer instead of checking the ID Token's signature. The function's options argument was removed.
    • Use the TLS server validation in processDeviceCodeResponse to validate the issuer instead of checking the optional ID Token's signature. The function's options argument was removed.
    • Use the TLS server validation in processIntrospectionResponse to validate the issuer instead of checking the optional JWT Introspection Response signature. The function's options argument was removed.
    • Use the TLS server validation in processRefreshTokenResponse to validate the issuer instead of checking the optional ID Token's signature. The function's options argument was removed.
    • Use the TLS server validation in processUserInfoResponse to validate the issuer instead of checking the optional JWT UserInfo Response signature. The function's options argument was removed.
    • PAR w/ DPoP no longer automatically adds dpop_jkt to the authorization request.
    • Removed calculateJwkThumbprint function export.
    • Removed jwksRequest function export.
    • Removed processJwksResponse function export.

    Refactor

    • remove ignored and unused exports (4a545df)
    • use TLS server validation instead of jwt signature validations (f728110)
    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Nov 20, 2022)

  • v1.4.0(Nov 8, 2022)

  • v1.3.0(Oct 31, 2022)

  • v1.2.2(Nov 4, 2022)

  • v1.2.1(Oct 10, 2022)

    This release

    • moves the package on npm from @panva/oauth4webapi to just oauth4webapi
    • moves the package on deno.land/x from doauth to oauth4webapi

    Otherwise this release contains only code refactoring and documentation updates.


    NB: @panva/oauth4webapi had last npm version released and it now simply re-exports oauth4webapi to allow existing consumers to obtain updates within the ^1.2.1 semver range.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Sep 14, 2022)

  • v1.1.4(Aug 26, 2022)

  • v1.1.3(Jul 20, 2022)

  • v1.1.2(Jul 12, 2022)

  • v1.1.1(Jul 4, 2022)

  • v1.1.0(Jun 28, 2022)

  • v1.0.5(Jun 17, 2022)

  • v1.0.4(Jun 9, 2022)

  • v1.0.3(May 23, 2022)

  • v1.0.2(May 19, 2022)

  • v1.0.1(May 18, 2022)

  • v1.0.0(May 18, 2022)

    This software is a collection of routines upon which framework-specific client modules may be written. Its objective is to support and, where possible, enforce secure and current best practices using only capabilities common to Browser and Non-Browser JavaScript-based runtime environments.

    Target profiles of this software are OAuth 2.1, OAuth 2.0 complemented by the latest Security BCP, and FAPI 2.0. Where applicable Open ID Connect is also supported.

    In Scope & Implemented

    • Authorization Server Metadata discovery
    • Authorization Code Flow (profiled under OpenID Connect 1.0, OAuth 2.0, OAuth 2.1, and FAPI 2.0), PKCE
    • Refresh Token, Device Authorization, and Client Credentials Grants
    • Demonstrating Proof-of-Possession at the Application Layer (DPoP)
    • Token Introspection and Revocation
    • Pushed Authorization Requests (PAR)
    • UserInfo and Protected Resource Requests
    • Authorization Server Issuer Identification
    • JWT Secured Introspection, Response Mode, Authorization Request, and UserInfo

    Out of scope

    • CommonJS
    • Implicit, Hybrid, and Resource Owner Password Credentials Flows
    • Mutual-TLS Client Authentication and Certificate-Bound Access Tokens
    • JSON Web Encryption (JWE)
    • JSON Web Signature (JWS) rarely used algorithms and HMAC
    • Automatic polyfills of any kind
    Source code(tar.gz)
    Source code(zip)
Owner
Filip Skokan
Identity, OpenID Connect, OAuth 2.0, SSO, Authorization, Authentication, Technical Standards. Node.js core collaborator.
Filip Skokan
A web app to post emoji implemented in connect-go and connect-web.

emotter Emotter is an app to post and share single emoji. This is an example app of connect. Example https://emotter.syumai.com API: Cloud Run Web cli

syumai 11 Oct 30, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Build Schema.org graphs for JavaScript Runtimes (Browser, Node, etc). Improve your sites SEO with quick and easy Rich Results.

schema-org-graph-js The quickest and easiest way to build Schema.org graphs for JavaScript Runtimes (Browser, Node, etc). Status: ?? In Development Pl

Harlan Wilton 17 Dec 21, 2022
Minimalistic pre-configured OAuth 2.0 client for Deno. Inspired by grant.

DenoGrant Minimalistic pre-configured OAuth 2.0 client for Deno. Inspired by Grant. NOTE: this is alpha software subject to breaking changes at anytim

CJ R. 12 Dec 13, 2022
Remix Auth plugin for Twitter OAuth 1.0a

Remix Auth Twitter Remix Auth plugin for Twitter OAuth 1.0a. Supported runtimes Runtime Has Support Node.js ✅ Cloudflare ✅ Demo Try out live demo (sou

na2hiro 13 Dec 31, 2022
Express middleware for easy OAuth with a variety of providers.

accounted4 Express middleware for easy OAuth2 with a variety of providers. accounted4 is intended to make it easy for developers to add third-party OA

Josh Moore 3 May 7, 2022
📋 Todo List CRUD and OAuth with Firebase

Todo List CRUD and OAuth with Firebase Esta es una app hecha con React y Firebase en la que puedas crear, leer, actualizar y borrar tareas dentro de u

Adonys Santos 4 May 28, 2022
Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services.

Tidbyt Client for Node.js Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services. Insta

Nicholas Penree 19 Dec 17, 2022
This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide the tool to submit a new score.

Leader Board: Hit the API! This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide t

Andrés Felipe Arroyave Naranjo 12 Apr 6, 2022
open-source ‌‌Javascript library to connect Alsat pardakht peyment API

Alsat IPG Node.js با استفاده از این پکیج میتوانید پروژه Node.js خودتون رو به شبکه پرداخت آل‌سات پرداخت وصل کنید و به راحتی محصولات خودتون رو داخل پروژ

Alsat Pardakht 3 Apr 4, 2022
Connect your Ethereum smart contract to any real world API using the oracle pattern!

Minimal Viable Oracle (MVO) - An effective way to Build your own oracle with Solidity Smart contracts cannot access off-chain data directly. This repo

Noah 9 Aug 25, 2022
Seamlessly connect your web server to Rebrandly so that you can re-use your domain name for both your app and your short links

rebrandly-express Seamlessly connect your web server to Rebrandly so that you can re-use your domain name for both your app and your short links Rebra

null 3 Dec 13, 2022
A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site

FRAGMENTED Summary A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site. Each user will b

null 2 Jan 24, 2022
Obsidian Web: Connect your browser with your Obsidian notes

Obsidian Web: Connect your browser with your Obsidian notes This is an unofficial Chrome extension for Obsidian that lets you send content from the we

Adam Coddington 97 Jan 3, 2023
Python based web application to import, connect and analyze manufacturing data from multiple data sources.

Analysis Platform Analysis Platform is an open source web application to import, connect and visualize factory IoT data. It helps to collect, link and

Analysis Platform +DN7 7 Dec 1, 2022
example app that creates a new player in Spotify Connect to play music from in the browse using Spotify Web Playback SDK.

Spotify Web Playback SDK Demo Requirements User must have Spotify Premium, DRM & EME supported and JavaScript enabled Web Browser. License Copyright 2

Sijey 8 Jul 20, 2022
📗 A simple electron app to connect with Platzi and add a discord rich presence

Platzi - Discord Rich Presence RPC Electron Requirements Nodejs you can download the latest version -> here clone the repository like this -> git clon

Jonathan Dyallo 9 Oct 31, 2022