Bdaya-Dev / oidc

Flutter OpenIdConnect plugin
https://bdaya-dev.github.io/oidc/
MIT License
24 stars 12 forks source link

Error trying fetch discovery document. #94

Closed bsutton closed 1 month ago

bsutton commented 1 month ago

Description

I'm using oicd to do auth against the xero saas (on linux)

I'm getting an error when oidc tries to access the discovery document.

I have the debugger set to catch 'All Exceptions' so I see several different exceptions before the final one.

I've listed them in the order the occur:

The

    final manager = OidcUserManager.lazy(
      discoveryDocumentUri: OidcUtils.getOpenIdConfigWellKnownUri(
        Uri.parse('https://identity.xero.com/.well-known/openid-configuration'),
      ),
      clientCredentials: OidcClientAuthentication.clientSecretBasic(
          clientId: system!.xeroClientId!,
          clientSecret: system.xeroClientSecret!),
      store: OidcDefaultStore(),
      settings: OidcUserManagerSettings(
          redirectUri: Uri.parse('hmb://xero/auth_callback')),

      // TODO: add other settings
    );

Exception 1

Exception  thrown during a call to NativeSocket.lookup
host: login.xero.com
response [-2, -2, "Name or service not known"

Exception 2:

Failed host lookup: 'identity.xero.com'

Exception 3:

Failed host lookup: 'login.xero.com'
Name or service not known

Exception 4: This error occurs when getPRoviderMetaData is called.

Unexpected character
Source: <!DOCTYPE HTML>
... full html page ...
_ChunkedJsonParser.fail (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/convert_patch.dart:1380)
_ChunkedJsonParser.parseNumber (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/convert_patch.dart:1247)
_ChunkedJsonParser.parse (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/convert_patch.dart:912)
_parseJson (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/_internal/vm/lib/convert_patch.dart:35)
JsonDecoder.convert (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/convert/json.dart:610)
JsonCodec.decode (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/convert/json.dart:216)
jsonDecode (/home/bsutton/snap/flutter/common/flutter/bin/cache/pkg/sky_engine/lib/convert/json.dart:155)
OidcEndpoints._handleResponse (/home/bsutton/.pub-cache/hosted/pub.dev/oidc_core-0.7.0/lib/src/endpoints/facade.dart:23)
OidcEndpoints.getProviderMetadata (/home/bsutton/.pub-cache/hosted/pub.dev/oidc_core-0.7.0/lib/src/endpoints/facade.dart:261)
<asynchronous gap> (Unknown Source:0)
OidcUserManagerBase.ensureDiscoveryDocument (/home/bsutton/.pub-cache/hosted/pub.dev/oidc_core-0.7.0/lib/src/managers/user_manager_base.dart:1026)
<asynchronous gap> (Unknown Source:0)
OidcUserManagerBase.init (/home/bsutton/.pub-cache/hosted/pub.dev/oidc_core-0.7.0/lib/src/managers/user_manager_base.dart:1233)
<asynchronous gap> (Unknown Source:0)
_XeroAuthScreenV2State._authenticate (/home/bsutton/git/handyman/handyman/lib/invoicing/xero_auth_v2.dart:86)
<asynchronous gap> (Unknown Source:0)

Exception 5: Failed to handle the response from endpoint: https://identity.xero.com/.well-known/openid-configuration/.well-known/openid-configuration

Request (GET https://identity.xero.com/.well-known/openid-configuration/.well-known/openid-configuration)


[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: OidcException: Couldn't fetch the discoveryDocument, extra: {discoveryDocumentUri: https://identity.xero.com/.well-known/openid-configuration/.well-known/openid-configuration}, error: null
#0      OidcUserManagerBase.logAndThrow (package:oidc_core/src/managers/user_manager_base.dart:92:5)
#1      OidcUserManagerBase.ensureDiscoveryDocument (package:oidc_core/src/managers/user_manager_base.dart:1033:9)
<asynchronous suspension>
#2      OidcUserManagerBase.init (package:oidc_core/src/managers/user_manager_base.dart:1233:7)
<asynchronous suspension>
#3      _XeroAuthScreenV2State._authenticate (package:hmb/invoicing/xero_auth_v2.dart:86:5)

Expected Behavior

I'm expecting the discovery phase to complete successfully.

Versions: 
  oidc: ^0.7.0
  oidc_core: ^0.7.0
  oidc_default_store: ^0.2.0+9

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.2, on Ubuntu 22.04.4 LTS 6.5.0-41-generic, locale en_AU.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.3)
[!] Android Studio (version unknown)
    ✗ Unable to determine Android Studio version.
    ✗ android-studio-dir = /home/bsutton/Android/Sdk
    ✗ Unable to find bundled Java version.
[✓] VS Code (version 1.90.2)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.
bsutton commented 1 month ago

Found the problem.

I was passing: https://identity.xero.com/.well-known/openid-configuration

rather than just : https://identity.xero.com