【发布时间】:2020-11-25 05:46:31
【问题描述】:
我创建了一个只有两个组件的 Angular 应用程序,登录和用户详细信息组件。只想显示登录的用户详细信息。每当我从应用程序单击登录按钮时,它都会将我重定向到 azure-client。在浏览器上获取以下重定向网址。请建议/推荐下一步?
app.module.ts
@NgModule({
declarations: [
LoginComponent,
UserDetailComponent,
AppComponent
],
imports: [
BrowserModule,
FormsModule,
RouterModule,
HttpClientModule,
ReactiveFormsModule,
AppRoutingModule,
MsalModule.forRoot({
auth: {
clientId: '************************************', // This is your client ID
authority: '********************************************', // This is your tenant info
redirectUri: 'http://localhost:4200/' // This is your redirect URI
},
cache: {
cacheLocation: 'localStorage'
},
}),
],
providers: [UserService,
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent]
})
export class AppModule { }
app.routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { UserDetailComponent } from './user-detail/user-detail.component';
const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'login', component: LoginComponent },
{ path: 'userDetail', component: UserDetailComponent },
{ path: '**', redirectTo: '' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
点击自定义UI的登录按钮会调用的登录方法
login(username, password) : Observable<any> {
let headers: HttpHeaders = new HttpHeaders();
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers = headers.append('Content-type', 'application/json');
headers = headers.append('Content-type', 'text/html');
headers = headers.append('Access-Control-Allow-Origin', '*');
headers = headers.append('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
headers = headers.append('Access-Control-Allow-Headers', '*');
headers = headers.append('Access-Control-Allow-Credentials', 'true');
return this.http.post<any>('http://localhost:8082/check', { username, password }, {headers})
.pipe(map(user => {
return user;
}));
}
【问题讨论】:
-
是的,我已按照这些步骤操作并相应地配置了我的应用程序。
-
请发布您的登录代码、app.module.ts 和 app-routing.module.ts
-
@corradolab 添加了所有文件
标签: angular azure spring-boot spring-security active-directory