Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Startup
- {
- private List<TestUser> GetTestUsers()
- {
- return new List<TestUser>
- {
- new TestUser
- {
- SubjectId = "1",
- Username = "test",
- Password = "password"
- }
- };
- }
- // This method gets called by the runtime. Use this method to add services to the container.
- // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddMvc();
- services.AddIdentityServer()
- .AddDeveloperSigningCredential()
- .AddInMemoryIdentityResources(GetIdentityResources())
- .AddInMemoryApiResources(GetApiResources())
- .AddInMemoryClients(GetClients())
- .AddTestUsers(GetTestUsers());
- services.AddAuthentication()
- .AddOpenIdConnect("oidc", "OpenID Connect", options =>
- {
- options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
- options.SignOutScheme = IdentityServerConstants.SignoutScheme;
- options.Authority = "http:localhost:44388";
- //??? this should match the client id, right?
- options.ClientId = "web-badders-rank";
- options.RequireHttpsMetadata = false; // for dev testing
- });
- }
- private IEnumerable<Client> GetClients()
- {
- return new List<Client>
- {
- new Client
- {
- ClientId = "web-badders-rank",
- ClientName = "Badders Rank Web Client",
- AllowedGrantTypes = GrantTypes.Implicit,
- AllowAccessTokensViaBrowser = true,
- RedirectUris = {"http://localhost:4002/signin-oidc"},
- AllowedCorsOrigins = {"http://localhost:4200"},
- AllowedScopes =
- {
- IdentityServerConstants.StandardScopes.OpenId,
- IdentityServerConstants.StandardScopes.Profile,
- "badders-rank-api"
- }
- }
- };
- }
- private IEnumerable<ApiResource> GetApiResources()
- {
- return new List<ApiResource>
- {
- new ApiResource("badders-rank-api", "Badders Rank Api")
- };
- }
- private IEnumerable<IdentityResource> GetIdentityResources()
- {
- return new List<IdentityResource>
- {
- new IdentityResources.OpenId(),
- new IdentityResources.Profile()
- };
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.UseIdentityServer();
- app.UseStaticFiles();
- AccountOptions.ShowLogoutPrompt = false;
- AccountOptions.AutomaticRedirectAfterSignOut = true;
- app.UseMvcWithDefaultRoute();
- }
- }
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddMvcCore()
- .AddJsonFormatters()
- .AddAuthorization();
- services.AddAuthentication("Bearer")
- .AddIdentityServerAuthentication(options =>
- {
- options.Authority = "http://localhost:44388";
- options.ApiName = "badders-rank-api";
- options.RequireHttpsMetadata = false;
- //options.RequireScope
- //options.TokenValidationParameters.NameClaimType = "name";
- });
- services.AddCors(option => option.AddPolicy("MyPolicy", builder =>
- {
- builder.WithOrigins("http://localhost:4200", "https://localhost:44388")
- .AllowAnyMethod()
- .AllowAnyHeader();
- }));
- services.AddScoped(typeof(IPlayerRepository), typeof(PlayerRepository));
- services.AddScoped(typeof(IGroupRepository), typeof(GroupRepository));
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.UseCors("MyPolicy");
- app.UseAuthentication();
- app.UseMvc();
- }
- }
- import {AuthConfig } from 'angular-oauth2-oidc';
- export const authConfig: AuthConfig = {
- issuer: 'http://localhost:44388',
- redirectUri: 'http://localhost:4200/signin-oidc',
- clientId: 'web-badders-rank',
- responseType : 'id_token token',
- scope: 'openid profile badders-rank-api'
- };
- export class AppComponent implements OnInit {
- title = 'Badders Rank';
- constructor(private oauthService: OAuthService) {
- // this.configureWithNewConfigApi();
- // console.log(this.oauthService.getAccessToken());
- }
- private configureWithNewConfigApi(): void {
- this.oauthService.configure(authConfig);
- this.oauthService.tokenValidationHandler = new JwksValidationHandler();
- this.oauthService.loadDiscoveryDocumentAndTryLogin();
- }
- ngOnInit(): void {
- // this.service.getGroupNames().then(res => {
- // this.groupNames = res;
- // });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement