Search code examples
meteorkeycloak

meteor keycloak third party


i want to test a keycloak request/response with a keycloak server in a docker file running on my localy machine.

The package Keycloak in atmospherejs doesnt work so i decided to include it to my meteor projekt as a third party library.

I put the library in a public/compatibility/keycloak/keycloak.js

The Autocomplete find it but if i use it then im getting a bug.

Exception while invoking method 'getTestToken' ReferenceError: Keycloak is not defined

But i do not understand it because it is correctly implemented as a thid party library in meteor. Can anybody help me to get this done?


Solution

  • Here I packaged the adapter library for meteor. Have not published it because I need to fork the original library and other stuff. Now you can call KeyCloak() on the client. Here's how I tested it in my router.js:

    import { Keycloak } from 'meteor/mutdmour:keycloak'
    
    Router.configure({
        waitOn: [
            function() {
                console.log(Keycloak());
            }
        ]
    });
    

    Here's what you can do to replicate what I did with other libraries:

    1. create a package, now you can find it in your packages folder

      meteor create --package mutdmour:keycloak

    2. copied over the keycloak.js into packages/keycloak

    3. changed the package.js file to reference the mainModule to run only on the client. This is why you are getting 'window is not defined'. Because it's running on the server. You could try putting that import in a if (Meteor.isClient()){...}

      api.mainModule('keycloak.js', 'client');

    4. added an export to package.js

      api.export('Keycloak', 'client');

    5. add the word export to the Keycloak definition in keycloak.js

      export var Keycloak =

    6. add the package

      meteor add mutdmour:keycloak