LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Custom Grant Types

Light-OAuth2 supports custom grant types and it is very easy to implement with a special client type called trusted. The trusted client type is an add-on based on the standard public or confidential client types provided in OAuth 2.0 specification.

The key condition to setup a trusted client is that the client and OAuth 2.0 provider are deployed in the same organization so that OAuth 2.0 provider can trust the client on certain custom grant types.

Currently, we have one custom grant type called client_authenticated_user.

client_authenticated_user

Before you use this grant type, you have to create a new client through client API and make sure the the client type is “trusted”.

Once the client is registered, you should have a client_id and client_secret returned from the endpoint. Please write down both especially client_secret as there is no way to recover it. The client secret is generated and the hashed and salted result is saved into the database table, so there is no way we can retrieve it later.

For information on client registration, please refer to client tutorial

To start the light-oauth2 services in a docker-compose, please refer to How to start services

Once the services are up and running, let’s create a brand new client and set the client type as trusted.

Here is the curl command line.

curl -k -H "Content-Type: application/json" -X POST -d '{"clientType":"trusted","clientProfile":"mobile","clientName":"Trusted Client Demo","clientDesc":"A demo client that is trused","scope":"t.r t.w","redirectUri": "https://localhost:8080/authorization","ownerId":"admin"}' https://localhost:6884/oauth2/client

The following is the example response and the clientId and clientSecret in your command would be different. Please write down the clientId and ClientSecret as subsequent commands need them.

{"clientId":"96058f8e-6c03-4b2f-b30e-25b8d093d6d2","clientSecret":"mkFLT99FS260txCk9zKt5A","clientType":"trusted","clientProfile":"mobile","clientName":"Trusted Client Demo","clientDesc":"A demo client that is trused","ownerId":"admin","scope":"t.r t.w","redirectUri":"https://localhost:8080/authorization","createDt":"2017-12-06","updateDt":null}

Given that we have created a trusted client, we are going to use this client to access token endpoint in order to generate a token with client_authenticated_user grant type.

Here is the command.

curl -k -H "Authorization: Basic 96058f8e-6c03-4b2f-b30e-25b8d093d6d2:mkFLT99FS260txCk9zKt5A" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d "grant_type=client_authenticated_user&userId=admin&userType=Employee&transit=12345" https://localhost:6882/oauth2/token

And the response is something like this.

{"access_token":"eyJraWQiOiIxMDAiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTUxMjUyODAzNSwianRpIjoiZE82c0hNZ3RqTENZUmVnT3QzUURyUSIsImlhdCI6MTUxMjUyNzQzNSwibmJmIjoxNTEyNTI3MzE1LCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6ImFkbWluIiwidXNlcl90eXBlIjoiRW1wbG95ZWUiLCJjbGllbnRfaWQiOiI5NjA1OGY4ZS02YzAzLTRiMmYtYjMwZS0yNWI4ZDA5M2Q2ZDIiLCJzY29wZSI6WyJ0LnIiLCJ0LnciXSwidHJhbnNpdCI6IjEyMzQ1In0.bDL7LCAEWSZiJPJGfMyr7DJeO6DKnKS5dEp_IRGiWHOaYv5sck6dExE-JMI4pwroY6tVuG7-fpZ3QobkAUdwOfInqFbQcz1NdusiaBmTty8-60dZQMjsORzVv41cnMRWxdmKL42GH1vcbkCG1YP9orMUEbbQ0wPILfnkNpD00hcIWIWfNMKlGml6vGxFtbTy2hIoL-MUObwBelDSveQ5hjNIavtw7jj5Uq3XfimIzN0LeTAe8kzGc4R_PQK5LnaS2Qk8Ys_KnoY_G6SKRB1JuvBwSiIjHYYvmfSeJz3kVGYaivVQHMMpafRnuddkuaaxe1IHTzLtUdQuiLCUZJ4lxA","refresh_token":"d9bd57f7-cd83-4aed-946a-30213c0703de","token_type":"bearer","expires_in":600}

You can decode the token at jwt.io site.

For more information on how to get the token with this custom grant type, you can check the test cases at https://github.com/networknt/light-oauth2/blob/master/token/src/test/java/com/networknt/oauth/token/handler/Oauth2TokenPostHandlerTest.java#L1030

Also, there is an standalone example built for one of our customers at https://github.com/networknt/light-example-4j/blob/master/client/tomcat/src/main/java/com/networknt/client/Http2ClientExample.java

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Custom Grant Types” was last updated: July 5, 2021: fixes #275 checked and corrected grammar/spelling for majority of pages (#276) (b3bbb7b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute