-
Notifications
You must be signed in to change notification settings - Fork 14
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.
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>
- Note the value of the
<CUSTOM_JWT_ISSUER>
token. - Note the value of the
<CUSTOM_JWT_AUDIENCE>
token. - Remove all of the tokens from the file.
- Save the file.
In the Services.Controllers
project you will find a file named AuthTools.dbl that contains a static class named AuthTools
.
-
Rename the file to
AuthenticationTools.dbl
. -
Edit the file and rename the class to
AuthenticationTools
. -
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
-
In the
GetIssuer
method, replace the textMyCompany
with the previous value of the<CUSTOM_JWT_ISSUER>
token. -
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:
-
Change the first parameter (probably "<CUSTOM_JWT_ISSUER>" right now) to pass
AuthenticationTools.GetIssuer()
-
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)
- Save the file
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.
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.
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information