manfredsteyer / angular-oauth2-oidc

Support for OAuth 2 and OpenId Connect (OIDC) in Angular.
MIT License
1.9k stars 686 forks source link

Cannoy mach any routes #194

Closed meron1122 closed 6 years ago

meron1122 commented 6 years ago

I configured as mentioned in getting started, and i redirected to my Oauth2 server, i login sucessfully but when i back to the angluar application i have issue error cannot match any routes. URL Segment 'access token' And redirect to login again. What i make wrong?

manfredsteyer commented 6 years ago

Do you use Routing in the hash fragment?

meron1122 commented 6 years ago

I am newbie in Angular, but i guess no. My routing:

 export const routes: Routes = [
    {
        path: '',
        redirectTo: 'page/dashboard',
        pathMatch: 'full'
    },
    {
        path: 'page',
        component: FullLayoutComponent,
        // canActivate: [AuthGuard],
        data: {
            title: 'Home'
        },
        children: [
            {
                path: 'dashboard',
                loadChildren: './dashboard/dashboard.module#DashboardModule'
            },
            {
                path: 'UsersList',
                loadChildren: './users/users-list/users-list.module#UsersListModule'
            },
            {
                path: 'MachinesList',
                loadChildren: './machines/machines-list/machines-list.module#MachinesListModule'
            },
            {
                path: 'MachinePrivileges',
                loadChildren: './machines/machine-privileges/machine-privileges.module#MachinePrivilegesModule'
            },
            {
                path: 'GroupsList',
                loadChildren: './groups/groups-list/groups-list.module#GroupsListModule'
            },
            {
                path: 'UserDetailDemo',
                loadChildren: './users/user-details/user-details.module#UserDetailsModule'
            }// ,
            // { path: '**', redirectTo: 'dashboard' }
        ],
    },
    { path: '**', redirectTo: 'dashboard' },
];

@NgModule({
    imports: [RouterModule.forRoot(routes, {enableTracing: true, useHash: false})],
    exports: [RouterModule]
})
export class AppRoutingModule {
}
manfredsteyer commented 6 years ago

Thx for this info. Can you check in your sample so that I can have a look at it?

meron1122 commented 6 years ago

Sample works fine, But funny thing: When i enable oidc, everything looks fine.

manfredsteyer commented 6 years ago

Did you turn it off before? I'm asking b/c it is on by default since some versions.

niclash commented 6 years ago

I am having a similar issue, except I am authenticating against Google and get the "state" can't be matched; Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'state'

BUT, I have 2 versions of the same application, and the first version works, the second doesn't. I can't find any differences in my code regarding OAuth. However, the application structure is quite different, so I suspect that there is something that is not called in the same order (or not at all) that is supposed to "take" the callback URI for processing.

If you have any pointers to docs that explains how the callback is handled in the library, or absent that, where in the code is the 'state' and 'access_token' URI parts being handled?

manfredsteyer commented 6 years ago

Hi @niclash Hi @meron1122

Can you provide a sample that shows that issue?

Can you try out this [1] with or without useHash:true ?

Best wishes, Manfred [1] https://manfredsteyer.github.io/angular-oauth2-oidc/angular-oauth2-oidc/docs/additional-documentation/routing-with-the-hashstrategy.html

niclash commented 6 years ago

If you send me your mail address to niclas@hedhman.org, I'll send you the whole thing (not very far yet)

niclash commented 6 years ago

As for routing-with-the-hashstrategy.html, I don't know how to use that, as I call initImplictFlow() on [login] click.

niclash commented 6 years ago

I just realized another difference between my two projects; Angular4 (works) and Angular5 (not working)

meron1122 commented 6 years ago

@manfredsteyer useHash:true option(true/false) nothing change. I have turned off oidc manual. But example attached in the sources library works fine. My example is exacly this project(+ my some subpages) https://github.com/mrholek/CoreUI-Angular

@niclash In case of desperate i migrated project from 4 to 5 and doesn't help, but i guess, i cat forgot upgrade some lib :)

niclash commented 6 years ago

So, I added RouterModule.forRoot(routes, {useHash: false, initialNavigation: false, enableTracing: true})

and in the setting up of oauth in app.component.ts

this.oauth.tryLogin().then(_ => { this.router.navigate(['/']); });

(which I don't understand the meaning of. Does it do the check when called or when implicitFlow reach that point?)

Anyway, I then pass the point of "can not match" and instead complaining about a missing "jwks parameter". But if I then remove the

this.oauth.tokenValidationHandler = new JwksValidationHandler();

then it redirects into the app (logged in).

niclash commented 6 years ago

I have gotten away from this. I ended up using hashStrategy because I was not paying attention. But I still can't get this library to work reliably. I am about to give up.