Create Custom REST API to generate bearer access token for custom username/attribute login

Hey Everyone,
I want to create a custom REST API to generate the bearer token. I am logging in keyclock using username and attribute. In response of this I want bearer token same as we get after login using the username and password,. Also I want to introduce new grant type for username and attribute login.
Is It possible to create such REST API ?