Hi,
I have a problem when I try to log in. I get bad requests with message
## Erreur : Le paramètre 'redirect_uri' doit être un URI de redirection de connexion dans les paramètres de l'application cliente : https://dev-*******-admin.okta.com/admin/app/oidc_client/instance/***********#tab-general
I use :
“@okta/okta-angular”: “^6.4.0”,
“@okta/okta-auth-js”: “^7.8.0”,
angular 17
node 18.13.0
typseScript 5.2.2
Part of my code is:
AppRoutingModule:
@NgModule({
imports: [
RouterModule.forRoot([ {
path: 'login/callback',
component: OktaCallbackComponent,
},
AppModule
import {
OKTA_CONFIG,
OktaAuthModule,
OktaConfig
} from '@okta/okta-angular';
import { OktaAuth } from '@okta/okta-auth-js';
const authConfig = {
clientId: '*****',
issuer: 'https://dev-*****.okta.com/oauth2/default',
redirectUri: 'http://localhost:4200/login/callback',
scopes: ['openid', 'profile', 'email','groups'],
pkce: true,
testing: {
disableHttpsCheck: false
},
resourceServer: {
basicUrl: 'http://localhost:8084/api',
}
}
const oktaAuth = new OktaAuth(authConfig);
const moduleConfig: OktaConfig = { oktaAuth };
@NgModule({
declarations: [
AppComponent, NotfoundComponent
],
imports: [
.......
OktaAuthModule.forRoot(moduleConfig)
],
providers: [
{
provide: OKTA_CONFIG,
useValue: { oktaAuth }
},
{ provide: LocationStrategy, useClass: HashLocationStrategy }
...
],
bootstrap: [AppComponent]
})
export class AppModule { }
AppComponent (ts)
import { OktaAuthStateService, OKTA_AUTH } from '@okta/okta-angular';
import OktaAuth from '@okta/okta-auth-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
isAuthenticated: boolean;
constructor( @Inject(OKTA_AUTH) public oktaAuth: OktaAuth, public authStateService: OktaAuthStateService, public router: Router) {
this.authStateService.authState$.subscribe((authState) => {
this.isAuthenticated = !!authState.isAuthenticated;
});
}
async ngOnInit() {
}
async login() {
await this.oktaAuth.signInWithRedirect();
}
async logout() {
await this.oktaAuth.signOut();
}
}
appComponent (html)
<a class="item" *ngIf="!isAuthenticated" (click)="oktaAuth.login('/')">Login</a>
{{isAuthenticated}}
<div *ngIf="isAuthenticated" >
<router-outlet></router-outlet>
</div>
when I access my app with http://localhost:4200 , I show a login button, but before I click it , I will be redirected to
(https://dev-xxxx.okta.com/oauth2/default/v1/authorize?client_id=xxxx&code_challenge=xxxx&code_challenge_method=S256&nonce=xxxx&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauthorization-code%2Fcallback&response_type=code&state=xxxx&scope=openid%20profile%20email%20groups)
with 400 bad request!!
The Okta login page is not displayed!
Can you please help me correct my code to obtain the login okta page when I click on “log in” button?
Note that I use the same config. , especially the redirect uri when I create Okta application
Thank you