Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
Implementation-IdentityServer4
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alan Farhadi
Implementation-IdentityServer4
Commits
f52498b3
Commit
f52498b3
authored
May 30, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add-implicit-flow
parent
8d6b9e82
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
232 additions
and
4 deletions
+232
-4
Authentication.sln
Authentication.sln
+8
-1
Configuration.cs
IdentityServer/Configuration.cs
+14
-1
AuthController.cs
IdentityServer/Controllers/AuthController.cs
+1
-2
HomeController.cs
JavascriptClient/Controllers/HomeController.cs
+22
-0
JavascriptClient.csproj
JavascriptClient/JavascriptClient.csproj
+15
-0
Program.cs
JavascriptClient/Program.cs
+26
-0
launchSettings.json
JavascriptClient/Properties/launchSettings.json
+27
-0
Startup.cs
JavascriptClient/Startup.cs
+35
-0
Index.cshtml
JavascriptClient/Views/Home/Index.cshtml
+11
-0
SignIn.cshtml
JavascriptClient/Views/Home/SignIn.cshtml
+12
-0
appsettings.Development.json
JavascriptClient/appsettings.Development.json
+9
-0
appsettings.json
JavascriptClient/appsettings.json
+10
-0
sign-in-callback.js
JavascriptClient/wwwroot/sign-in-callback.js
+16
-0
sign-in.js
JavascriptClient/wwwroot/sign-in.js
+26
-0
No files found.
Authentication.sln
View file @
f52498b3
...
...
@@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiOne", "ApiOne\ApiOne.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiTwo", "ApiTwo\ApiTwo.csproj", "{F0813394-EC56-461F-BE36-CE7E229C46B8}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -49,6 +51,10 @@ Global
{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.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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -60,6 +66,7 @@ Global
{E2FD0592-0C76-4D1C-9C3E-5A8FECA85D3E} = {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}
{CD1F92E9-68B8-40DB-B2FB-B4F3060F25FF} = {BAE8199D-D3C7-4D71-9A3E-7DC76A54EDDF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {503F7386-5516-4A48-B303-EB2EBBB70E07}
...
...
IdentityServer/Configuration.cs
View file @
f52498b3
...
...
@@ -56,7 +56,20 @@ namespace IdentityServer
//AlwaysIncludeUserClaimsInIdToken=true,
AllowOfflineAccess
=
true
,
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
},
};
}
}
IdentityServer/Controllers/AuthController.cs
View file @
f52498b3
...
...
@@ -33,7 +33,7 @@ namespace IdentityServer.Controllers
//check if model is exsist
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
vm
.
Username
,
vm
.
Password
,
false
,
false
);
if
(
result
.
IsNotAllow
ed
)
if
(
result
.
Succeed
ed
)
{
return
Redirect
(
vm
.
ReturnUrl
);
}
...
...
@@ -64,7 +64,6 @@ namespace IdentityServer.Controllers
if
(
result
.
Succeeded
)
{
await
_signInManager
.
SignInAsync
(
user
,
false
);
return
Redirect
(
vm
.
ReturnUrl
);
}
...
...
JavascriptClient/Controllers/HomeController.cs
0 → 100644
View file @
f52498b3
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
JavascriptClient/JavascriptClient.csproj
0 → 100644
View file @
f52498b3
<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>
JavascriptClient/Program.cs
0 → 100644
View file @
f52498b3
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
>();
});
}
}
JavascriptClient/Properties/launchSettings.json
0 → 100644
View file @
f52498b3
{
"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"
}
}
}
}
JavascriptClient/Startup.cs
0 → 100644
View file @
f52498b3
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
();
});
}
}
}
JavascriptClient/Views/Home/Index.cshtml
0 → 100644
View file @
f52498b3
@{
ViewData["Title"] = "Index";
}
<h1>Home Index</h1>
<button onclick="signIn()">SignIn</button>
<script src="~/sign-in.js"></script>
\ No newline at end of file
JavascriptClient/Views/Home/SignIn.cshtml
0 → 100644
View file @
f52498b3
<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>
JavascriptClient/appsettings.Development.json
0 → 100644
View file @
f52498b3
{
"Logging"
:
{
"LogLevel"
:
{
"Default"
:
"Information"
,
"Microsoft"
:
"Warning"
,
"Microsoft.Hosting.Lifetime"
:
"Information"
}
}
}
JavascriptClient/appsettings.json
0 → 100644
View file @
f52498b3
{
"Logging"
:
{
"LogLevel"
:
{
"Default"
:
"Information"
,
"Microsoft"
:
"Warning"
,
"Microsoft.Hosting.Lifetime"
:
"Information"
}
},
"AllowedHosts"
:
"*"
}
JavascriptClient/wwwroot/sign-in-callback.js
0 → 100644
View file @
f52498b3
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
JavascriptClient/wwwroot/sign-in.js
0 → 100644
View file @
f52498b3
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment