Commit f52498b3 authored by alan.f's avatar alan.f

add-implicit-flow

parent 8d6b9e82
...@@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiOne", "ApiOne\ApiOne.csp ...@@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiOne", "ApiOne\ApiOne.csp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiTwo", "ApiTwo\ApiTwo.csproj", "{F0813394-EC56-461F-BE36-CE7E229C46B8}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiTwo", "ApiTwo\ApiTwo.csproj", "{F0813394-EC56-461F-BE36-CE7E229C46B8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcClient", "MvcClient\MvcClient.csproj", "{592538AC-4F87-4642-B9F5-0A94C31262A7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcClient", "MvcClient\MvcClient.csproj", "{592538AC-4F87-4642-B9F5-0A94C31262A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavascriptClient", "JavascriptClient\JavascriptClient.csproj", "{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -49,6 +51,10 @@ Global ...@@ -49,6 +51,10 @@ Global
{592538AC-4F87-4642-B9F5-0A94C31262A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {592538AC-4F87-4642-B9F5-0A94C31262A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{592538AC-4F87-4642-B9F5-0A94C31262A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {592538AC-4F87-4642-B9F5-0A94C31262A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{592538AC-4F87-4642-B9F5-0A94C31262A7}.Release|Any CPU.Build.0 = Release|Any CPU {592538AC-4F87-4642-B9F5-0A94C31262A7}.Release|Any CPU.Build.0 = Release|Any CPU
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -60,6 +66,7 @@ Global ...@@ -60,6 +66,7 @@ Global
{E2FD0592-0C76-4D1C-9C3E-5A8FECA85D3E} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF} {E2FD0592-0C76-4D1C-9C3E-5A8FECA85D3E} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF}
{F0813394-EC56-461F-BE36-CE7E229C46B8} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF} {F0813394-EC56-461F-BE36-CE7E229C46B8} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF}
{592538AC-4F87-4642-B9F5-0A94C31262A7} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF} {592538AC-4F87-4642-B9F5-0A94C31262A7} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF}
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {503F7386-5516-4A48-B303-EB2EBBB70E07} SolutionGuid = {503F7386-5516-4A48-B303-EB2EBBB70E07}
......
...@@ -56,7 +56,20 @@ namespace IdentityServer ...@@ -56,7 +56,20 @@ namespace IdentityServer
//AlwaysIncludeUserClaimsInIdToken=true, //AlwaysIncludeUserClaimsInIdToken=true,
AllowOfflineAccess=true, AllowOfflineAccess=true,
RequireConsent=false RequireConsent=false
} },
new Client
{
ClientId="client_id_js",
AllowedGrantTypes = GrantTypes.Implicit,
RedirectUris={ "https://localhost:44387/Home/signin" },
AllowedScopes={
IdentityServerConstants.StandardScopes.OpenId,
"ApiOne",
},
AllowAccessTokensViaBrowser=true,
RequireConsent=false
},
}; };
} }
} }
...@@ -33,7 +33,7 @@ namespace IdentityServer.Controllers ...@@ -33,7 +33,7 @@ namespace IdentityServer.Controllers
//check if model is exsist //check if model is exsist
var result = await _signInManager.PasswordSignInAsync(vm.Username, vm.Password, false, false); var result = await _signInManager.PasswordSignInAsync(vm.Username, vm.Password, false, false);
if (result.IsNotAllowed) if (result.Succeeded)
{ {
return Redirect(vm.ReturnUrl); return Redirect(vm.ReturnUrl);
} }
...@@ -64,7 +64,6 @@ namespace IdentityServer.Controllers ...@@ -64,7 +64,6 @@ namespace IdentityServer.Controllers
if (result.Succeeded) if (result.Succeeded)
{ {
await _signInManager.SignInAsync(user, false); await _signInManager.SignInAsync(user, false);
return Redirect(vm.ReturnUrl); return Redirect(vm.ReturnUrl);
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace JavascriptClient.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult SignIn()
{
return View();
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace JavascriptClient
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55456",
"sslPort": 44387
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"JavascriptClient": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace JavascriptClient
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
}
}
}

@{
ViewData["Title"] = "Index";
}
<h1>Home Index</h1>
<button onclick="signIn()">SignIn</button>
<script src="~/sign-in.js"></script>
\ No newline at end of file
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.9.1/oidc-client.min.js"></script>
<script>var userManger = new Oidc.UserManager({
userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
response_mode: "query"
});
userManger.signinCallback().then(res => {
console.log(res);
window.location.href = '/home/index';
})</script>
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
var extractTokens = function (address) {
var returnValue = address.split('#')[1];
var values = returnValue.split('&');
for (var i = 0; i < values.length; i++) {
var v = values[i];
var kvPair = v.split('=');
localStorage.setItem(kvPair[0], kvPair[1]);
}
window.location.href = '/home/index';
}
extractTokens(window.location.href);
\ No newline at end of file
var createState = function () {
return "SessionValueMakeItABitLongerasdfhjsadoighasdifjdsalkhrfakwelyrosdpiufghasidkgewr";
};
var createNonce = function () {
return "NonceValuedsafliudsayatroiewewryie123";
};
var signIn = function () {
var redirectUri = "https://localhost:44387/Home/SignIn";
var responseType = "id_token token";
var scope = "openid ApiOne";
var authUrl =
"/connect/authorize/callback" +
"?client_id=client_id_js" +
"&redirect_uri=" + encodeURIComponent(redirectUri) +
"&response_type=" + encodeURIComponent(responseType) +
"&scope=" + encodeURIComponent(scope) +
"&nonce=" + createNonce() +
"&state=" + createState();
var returnUrl = encodeURIComponent(authUrl);
console.log(returnUrl);
window.location.href = "https://localhost:44325/Auth/Login?ReturnUrl=" + returnUrl;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment