首先,在应用程序的Facebook开发人员帐户中创建一个新的应用程序,为其生成一个应用程序ID和应用程序密码。
在Angular应用程序的环境文件中添加以下Facebook应用程序ID和应用程序密码:
export const environment = {
production: false,
apiUrl: 'http://localhost:5000/api/',
facebookAppId: 'YOUR_FACEBOOK_APP_ID_HERE',
facebookAppSecret: 'YOUR_FACEBOOK_APP_SECRET_HERE'
};
services.AddAuthentication().AddFacebook(options =>
{
options.AppId = Configuration["Facebook:AppId"];
options.AppSecret = Configuration["Facebook:AppSecret"];
})
.AddIdentityServerAuthentication(options =>
{
options.Authority = "https://localhost:5001";
options.RequireHttpsMetadata = true;
options.ApiName = "api";
options.ApiSecret = "apisecret";
});
new Client
{
ClientId = "angular_spa",
ClientName = "Angular SPA Client",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris = { "https://localhost:4200/auth-callback" },
PostLogoutRedirectUris = { "https://localhost:4200/" },
AllowedCorsOrigins = { "https://localhost:4200" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"api"
},
RequireConsent = false,
AllowAccessTokensViaBrowser = true
},
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth/auth.service