Skip to content

Updating to 3.1.90 With Custom Authentication

Steve Ives edited this page Apr 28, 2020 · 5 revisions

Harmony Core Logo

Updating to 3.1.90 With Custom Authentication

Prior to version 3.1.90, implementing custom authentication was a completely manual process, and we have assisted several developers to implement such a solution following a similar pattern.

In version 3.1.90 we added the ability to implement custom authentication via initial code generation, and while the implementation is very similar to the previously used manual pattern, we did make some small improvements that will require you to make some small changes to your current environment.

After using the project upgrade tool to upgrade to version 3.1.90, and after regenerating your code, you will find that the Services project fails to build because code in the Startup class is attempting to call two methods, AuthenticationTools.GetIssuer() and AuthenticationTools.GetAudience(). These methods won't exist in your current environment.

Edit UserDefinedTokens.tkn

Look for any user defined tokend in the file where the name starts with <CUSTOM_JWT_. Depending on the implementation you should find some or all of these tokens:

<CUSTOM_JWT_ISSUER>
<CUSTOM_JWT_AUDIENCE>
<CUSTOM_JWT_SECRET>
<CUSTOM_JWT_KEYGEN>
  1. Note the value of the <CUSTOM_JWT_ISSUER> token.
  2. Note the value of the <CUSTOM_JWT_AUDIENCE> token.
  3. Remove all of the tokens from the file.
  4. Save the file.

Rename AuthTools.dbl to AuthenticationTools.dbl

In the Services.Controllers project you will find a file named AuthTools.dbl that contains a static class named AuthTools.

  1. Rename the file to AuthenticationTools.dbl.

  2. Edit the file and rename the class to AuthenticationTools.

  3. Add the following two new methods to the top of the class:

    public static method GetIssuer, string
    proc
        ;TODO: Set the name of the "issuer" of the JWT. This is frequently the name of an organization.
        mreturn "MyCompany"
    endmethod

    public static method GetAudience, string
    proc
        ;TODO: Set the name of the "audience" of the JWT. This is frequently the name of an API or service.
        mreturn "MyApi"
    endmethod

  1. In the GetIssuer method, replace the text MyCompany with the previous value of the <CUSTOM_JWT_ISSUER> token.

  2. In the GetAudience method, replace the text MyApi with the previous value of the <CUSTOM_JWT_AUDIENCE> token.

Now look towards the bottom of the code for a call to CreateJwtSecurityToken, and:

  1. Change the first parameter (probably "<CUSTOM_JWT_ISSUER>" right now) to pass AuthenticationTools.GetIssuer()

  2. Change the seconf parameter (probably "<CUSTOM_JWT_AIDIENCE>" right now) to pass AuthenticationTools.GetAudience()

Like this:

data betterToken = handler.CreateJwtSecurityToken(AuthenticationTools.GetIssuer(), AuthenticationTools.GetAudience(), ident, new Nullable<DateTime>(current),new Nullable<DateTime>(theFuture), new Nullable<DateTime>(DateTime.Now), credentials, ^null)
  1. Save the file

Update Calls to GetToken

The final step is to search for any calls to the GetToken method and update the call to use AuthenticationTools.GetToken. You will most likely find this call in whatever controller class is used to retrieve access tokens. For example in some environments that class is named AuthenticateController.dbl.

Build and Test

Having made these changes your custom authentication code should once again build and operate as normal. If you have any issues with this process, please contact Steve Ives or Jeff Greene.

Clone this wiki locally