Password Grant
Reference: https://oauth.net/2/grant-types/password/ (opens in a new tab)
This grant is a great user experience for trusted first party clients both on the web and in native applications.
Password grant also usually called Resource Owner or Password Credentials grant.
Flow
The client will ask the user for their authorization credentials (usually a username and password).
The client then sends a POST request with following body parameters to the authorization server:
grant_typewith the valuepasswordclient_idwith the client’s IDclient_secretwith the client’s secretscopewith a space-delimited list of requested scope permissions.usernamewith the user’s usernamepasswordwith the user’s password
The authorization server will respond with a JSON object containing the following properties:
token_typewith the valueBearerexpires_inwith an integer representing the TTL of the access tokenaccess_tokena JWT signed with the authorization server’s private keyrefresh_tokenan encrypted payload that can be used to refresh the access token when it expires.
Setup
To apply this grant type, use the withPasswordGrant function builder.
$config = Heimdall::withAuthorizationConfig(
new ClientRepository(), // ClientRepository instance
new AccessTokenRepository(), // AccessTokenRepository instance
new ScopeRepository(), // ScopeRepository instance
__DIR__ . "/private.key" // private.key string path
);
$grant = Heimdall::withPasswordGrant(
new UserRepository(), // UserRepository instance
new RefreshTokenRepository() // RefreshTokenRepository instance
);
return Heimdall::initializeAuthorizationServer($config, $grant);