I have a login form in angular where I pass username and password, and I have an auth.service where I perform the login flow, I am using angular-oauth2-oidc and the fetchTokenUsingPasswordFlowAndLoadUserProfile method where I pass the email and password parameters , but it gives me the following error:
“The client is not authorized to use the provided grant type. Configured grant types: [refresh_token, implicit, authorization_code, interaction_code].”
Your Angular app is trying to use Resource Owner Password Grant? Why aren’t you using Authorization Code flow with PKCE instead, that’s what’s recommend for SPAs (and Native apps).
@andrea , I’m already using @okta/okta-auth-js for angular, the method: signInWithCredentials, where I can get a sessionToken, but I need an accessToken so I can send it to my API service. How can I get the accessToken? try to use the getAccessToken() method of OktaAuth but it gives me an undefined message…
what about borrowing a bit of the sample code here, to check if isLoginRedirect (which will check if Okta has already redirected back tot he app with code and state) before you call signInWithCredentials:
if (authClient.isLoginRedirect()) {
try {
await authClient.handleRedirect();
} catch (e) {
// log or display error details
}
} else if (!await authClient.isAuthenticated()) {
// Start the browser based oidc flow, then parse tokens from the redirect callback url
authClient.signInWithRedirect(); //this would change to signInWithCredentials
} else {
// User is authenticated
}
You would then add your custom logic to let the back-end handle the /token request in place of the handleRedirect method call