{"action":"opened","issue":{"url":"https://api.github.com/repos/IdentityServer/IdentityServer4.Samples/issues/219","repository_url":"https://api.github.com/repos/IdentityServer/IdentityServer4.Samples","labels_url":"https://api.github.com/repos/IdentityServer/IdentityServer4.Samples/issues/219/labels{/name}","comments_url":"https://api.github.com/repos/IdentityServer/IdentityServer4.Samples/issues/219/comments","events_url":"https://api.github.com/repos/IdentityServer/IdentityServer4.Samples/issues/219/events","html_url":"https://github.com/IdentityServer/IdentityServer4.Samples/issues/219","id":263358631,"number":219,"title":"Implict flow with angular client not working","user":{"login":"stt106","id":10818648,"avatar_url":"https://avatars0.githubusercontent.com/u/10818648?v=4","gravatar_id":"","url":"https://api.github.com/users/stt106","html_url":"https://github.com/stt106","followers_url":"https://api.github.com/users/stt106/followers","following_url":"https://api.github.com/users/stt106/following{/other_user}","gists_url":"https://api.github.com/users/stt106/gists{/gist_id}","starred_url":"https://api.github.com/users/stt106/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stt106/subscriptions","organizations_url":"https://api.github.com/users/stt106/orgs","repos_url":"https://api.github.com/users/stt106/repos","events_url":"https://api.github.com/users/stt106/events{/privacy}","received_events_url":"https://api.github.com/users/stt106/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-06T07:31:49Z","updated_at":"2017-10-06T07:31:49Z","closed_at":null,"author_association":"NONE","body":"Thanks for quickly updating to core 2.0!\r\n\r\nI'm using an angular 4 client so tried to follow the JsClient example as they shall be very similar but not sure what I did wrong. My two problems are:\r\n1. When I initiate a log in request from the angular client, it doesn't auto redirect to the Identity server sign in page.\r\n2. Probably a consequence of 1), I get unauthorized error when the angular client is making an api call on sign-in redirect.\r\n\r\nBtw, why is ClientId set to \"implicit\" on line 40 at https://github.com/IdentityServer/IdentityServer4.Samples/blob/release/Quickstarts/7_JavaScriptClient/src/QuickstartIdentityServer/Startup.cs ? It that a typo?\r\n\r\nBelow is my code:\r\nTo begin with, this is the Startup.cs for my identity server (configured to localhost:44388) using core 2.0 and identityserver4 2.0 and the latest QuickStartUI.\r\n```\r\npublic class Startup\r\n    {\r\n\r\n        private List<TestUser> GetTestUsers()\r\n        {\r\n            return new List<TestUser>\r\n            {\r\n                new TestUser\r\n                {\r\n                    SubjectId = \"1\",\r\n                    Username = \"test\",\r\n                    Password = \"password\"\r\n                }\r\n            };\r\n        }\r\n\r\n        // This method gets called by the runtime. Use this method to add services to the container.\r\n        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMvc();\r\n            services.AddIdentityServer()\r\n                    .AddDeveloperSigningCredential()\r\n                    .AddInMemoryIdentityResources(GetIdentityResources())\r\n                    .AddInMemoryApiResources(GetApiResources())\r\n                    .AddInMemoryClients(GetClients())\r\n                    .AddTestUsers(GetTestUsers());\r\n\r\n            services.AddAuthentication()\r\n                .AddOpenIdConnect(\"oidc\", \"OpenID Connect\", options =>\r\n                {\r\n                    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;\r\n                    options.SignOutScheme = IdentityServerConstants.SignoutScheme;\r\n                    options.Authority = \"http:localhost:44388\";\r\n                    //??? this should match the client id, right?\r\n                    options.ClientId = \"web-badders-rank\"; \r\n                    options.RequireHttpsMetadata = false; // for dev testing\r\n                });\r\n        }\r\n\r\n        private IEnumerable<Client> GetClients()\r\n        {\r\n            return new List<Client>\r\n            {\r\n                new Client\r\n                {\r\n                    ClientId = \"web-badders-rank\",\r\n                    ClientName = \"Badders Rank Web Client\",\r\n                    AllowedGrantTypes = GrantTypes.Implicit,\r\n                    AllowAccessTokensViaBrowser = true,\r\n                    RedirectUris = {\"http://localhost:4002/signin-oidc\"},\r\n                    AllowedCorsOrigins = {\"http://localhost:4200\"},\r\n                    AllowedScopes =\r\n                    {\r\n                        IdentityServerConstants.StandardScopes.OpenId,\r\n                        IdentityServerConstants.StandardScopes.Profile,\r\n                        \"badders-rank-api\"\r\n                    }\r\n                }\r\n            };\r\n        }\r\n\r\n        private IEnumerable<ApiResource> GetApiResources()\r\n        {\r\n            return new List<ApiResource>\r\n            {\r\n                new ApiResource(\"badders-rank-api\", \"Badders Rank Api\")\r\n            };\r\n        }\r\n\r\n        private IEnumerable<IdentityResource> GetIdentityResources()\r\n        {\r\n            return new List<IdentityResource>\r\n            {\r\n                new IdentityResources.OpenId(),\r\n                new IdentityResources.Profile()\r\n            };\r\n        }\r\n\r\n        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env)\r\n        {\r\n            if (env.IsDevelopment())\r\n            {\r\n                app.UseDeveloperExceptionPage();\r\n            }\r\n            app.UseIdentityServer();\r\n            app.UseStaticFiles();\r\n            AccountOptions.ShowLogoutPrompt = false;\r\n            AccountOptions.AutomaticRedirectAfterSignOut = true;\r\n            app.UseMvcWithDefaultRoute();\r\n        }\r\n    }\r\n```\r\n\r\nAnd this is the Startup.cs for my api (configured to run on localhost:5001)\r\n```\r\npublic class Startup\r\n    {\r\n        public Startup(IConfiguration configuration)\r\n        {\r\n            Configuration = configuration;\r\n        }\r\n\r\n        public IConfiguration Configuration { get; }\r\n\r\n        // This method gets called by the runtime. Use this method to add services to the container.\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddMvcCore()\r\n                    .AddJsonFormatters()\r\n                    .AddAuthorization();\r\n\r\n            services.AddAuthentication(\"Bearer\")\r\n                .AddIdentityServerAuthentication(options =>\r\n                {\r\n                    options.Authority = \"http://localhost:44388\";\r\n                    options.ApiName = \"badders-rank-api\";\r\n                    options.RequireHttpsMetadata = false;\r\n                    //options.RequireScope\r\n                    //options.TokenValidationParameters.NameClaimType = \"name\";\r\n                });\r\n            \r\n\r\n            services.AddCors(option => option.AddPolicy(\"MyPolicy\", builder =>\r\n            {\r\n                builder.WithOrigins(\"http://localhost:4200\", \"https://localhost:44388\")\r\n                        .AllowAnyMethod()\r\n                        .AllowAnyHeader();\r\n            }));\r\n\r\n            services.AddScoped(typeof(IPlayerRepository), typeof(PlayerRepository));\r\n            services.AddScoped(typeof(IGroupRepository), typeof(GroupRepository));\r\n        }\r\n\r\n        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.\r\n        public void Configure(IApplicationBuilder app, IHostingEnvironment env)\r\n        {\r\n            if (env.IsDevelopment())\r\n            {\r\n                app.UseDeveloperExceptionPage();\r\n            }\r\n            app.UseCors(\"MyPolicy\");\r\n            \r\n            app.UseAuthentication();\r\n            \r\n            app.UseMvc();\r\n        }\r\n    }\r\n```\r\n\r\nDon't think the problem is with the client side but for completeness, I am using a package called 'angular-oauth2-oidc' to initiate the implicit flow:\r\n```\r\nimport {AuthConfig } from 'angular-oauth2-oidc';\r\n\r\nexport const authConfig: AuthConfig = {\r\n    issuer: 'http://localhost:44388',\r\n    redirectUri: 'http://localhost:4200/signin-oidc',\r\n    clientId: 'web-badders-rank',\r\n    responseType : 'id_token token',\r\n    scope: 'openid profile badders-rank-api'\r\n};\r\n\r\nexport class AppComponent implements OnInit {\r\n  title = 'Badders Rank';\r\n  constructor(private oauthService: OAuthService) {\r\n    // this.configureWithNewConfigApi();\r\n    // console.log(this.oauthService.getAccessToken());\r\n  }\r\n  private configureWithNewConfigApi(): void {\r\n    this.oauthService.configure(authConfig);\r\n    this.oauthService.tokenValidationHandler = new JwksValidationHandler();\r\n    this.oauthService.loadDiscoveryDocumentAndTryLogin();\r\n  }\r\n  ngOnInit(): void {\r\n    // this.service.getGroupNames().then(res => {\r\n    //   this.groupNames = res;\r\n    // });\r\n  }\r\n}\r\n```"}}
{"actor":{"display_login":"stt106"}}