KaiOS open ID Authentication

54 Views Asked by At

We are developing a KaiOS mobile app using preact JS (//preactjs.com/) so we are trying to connect to an open id using AppAuth-JS (https://github.com/openid/AppAuth-JS) which is working fine but when i am trying to redirect from the open id callback page to my app i am facing issue in redirection . So i have tried using redirects in manifest.webapp but since the URL is dynamic i am guessing that is the reason it is not redirecting to my app.

CallBack URL : abc.com?code={alphanumericode}

Please can someone help me out with this redirection or if there is any other way i can achieve this ?

Any help will be really appreciated , Thank You

i have tried using manifest.webapp redirects property but that is not working.

"redirects": [
    {
      "from": "http//abc.com/callback?code=2121",
      "to": "/index.html/#/dashboard"
    }
  ]

AppAuth JS code below;

import { NoHashQueryStringUtils } from "./noHashQueryStringUtils";
import {
  AuthorizationServiceConfiguration,
  RedirectRequestHandler,
  AuthorizationNotifier,
  AuthorizationRequest,
  LocalStorageBackend,
  DefaultCrypto,
} from "@openid/appauth";
import { refreshStyles } from "less";

const authorizationHandler = new RedirectRequestHandler(
  new LocalStorageBackend(),
  new NoHashQueryStringUtils(),
  window.location,
  new DefaultCrypto()
);

const notifier = new AuthorizationNotifier();
authorizationHandler.setAuthorizationNotifier(notifier);
notifier.setAuthorizationListener((request, response, error) => {
  if (response) {
    console.log("Authorization successful:", response);
  }
});

export const Authentication = () => {
  useEffect(() => {
    navigator.spatialNavigationEnabled = true;
    const config = new AuthorizationServiceConfiguration({
      authorization_endpoint:auth_url,
    });
    //console.log('auth config received',response)
    const authRequest = new AuthorizationRequest({
      client_id: "xxx-xxx",
      redirect_uri: "/callback",
      scope: "xxx",
      response_type: AuthorizationRequest.RESPONSE_TYPE_CODE,
      state: undefined,
    });
    authorizationHandler.performAuthorizationRequest(config, authRequest);
  }, []);
0

There are 0 best solutions below