panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

Always return an error saying please use an absolute URL #590

Closed 19901025 closed 1 year ago

19901025 commented 1 year ago

I am using late create-react-app template to create a react web app and I am trying to use duender server authentication as authorization provider.

Inorder to access the duende server token endpoint I am using openid-client library. But I am getting following error when trying to discover url. const issuer = await Issuer.discover('https://localhost:5443/');

request.js:68 Uncaught (in promise) TypeError: only valid absolute URLs can be requested at Issuer.request (request.js:68:1) at Issuer.discover (issuer.js:171:1) at initializeClient (App.tsx:11:1) at App.tsx:28:1 at commitHookEffectListMount (react-dom.development.js:23150:1) at commitPassiveMountOnFiber (react-dom.development.js:24926:1) at commitPassiveMountEffects_complete (react-dom.development.js:24891:1) at commitPassiveMountEffects_begin (react-dom.development.js:24878:1) at commitPassiveMountEffects (react-dom.development.js:24866:1) at flushPassiveEffectsImpl (react-dom.development.js:27039:1)

I used config-overrides.js to change webpack overrides because of initial compilation errors I got.

const path = require('path'); const webpack = require('webpack'); const { URL } = require('url-polyfill');

module.exports = function override(config, env) { // Add fallbacks for the 'assert' and 'crypto' modules config.resolve.fallback = { ...config.resolve.fallback, assert: require.resolve('assert/'), crypto: require.resolve('crypto-browserify'), buffer: require.resolve("buffer"), http: require.resolve("stream-http"), https: require.resolve("https-browserify"), process: require.resolve('process/browser'), util: require.resolve("util/"), url: require.resolve("url/"), querystring: require.resolve("querystring-es3"), stream: require.resolve("stream-browserify"), };

config.resolve.extensions=[...config.resolve.extensions,'.ts', '.js'];

config.plugins.push(...config.plugins,new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'], }), new webpack.ProvidePlugin({ process: 'process/browser', }), new webpack.ProvidePlugin({ URL: [ 'url-polyfill', 'URL' ] }) );

return config; };

I need to know any fix or is there any better way to do this?

panva commented 1 year ago

Hi @19901025, this is Node.js module, not intended to run in a browser.