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
dab5a2ca
Commit
dab5a2ca
authored
Jun 01, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add-signout
parent
b086707d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
15 deletions
+43
-15
Configuration.cs
IdentityServer/Configuration.cs
+3
-1
AuthController.cs
IdentityServer/Controllers/AuthController.cs
+24
-4
Startup.cs
IdentityServer/Startup.cs
+2
-1
Login.cshtml
IdentityServer/Views/Auth/Login.cshtml
+3
-3
main.js
JavascriptClient/wwwroot/main.js
+4
-4
HomeController.cs
MvcClient/Controllers/HomeController.cs
+5
-0
Startup.cs
MvcClient/Startup.cs
+2
-2
No files found.
IdentityServer/Configuration.cs
View file @
dab5a2ca
...
...
@@ -45,6 +45,7 @@ namespace IdentityServer
ClientSecrets
={
new
Secret
(
"client_secret_mvc"
.
ToSha256
())},
AllowedGrantTypes
=
GrantTypes
.
Code
,
RedirectUris
={
"https://localhost:44349/signin-oidc"
},
PostLogoutRedirectUris
={
"https://localhost:44349/Home/Index"
},
AllowedScopes
={
"ApiOne"
,
"ApiTwo"
,
...
...
@@ -64,7 +65,8 @@ namespace IdentityServer
AllowedGrantTypes
=
GrantTypes
.
Implicit
,
RedirectUris
={
"https://localhost:44387/Home/signin"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
PostLogoutRedirectUris
={
"https://localhost:44387/Home/Idex"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
AllowedScopes
={
IdentityServerConstants
.
StandardScopes
.
OpenId
,
...
...
IdentityServer/Controllers/AuthController.cs
View file @
dab5a2ca
...
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Threading.Tasks
;
using
IdentityServer.ViewModels
;
using
IdentityServer4.Services
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
...
...
@@ -12,13 +13,16 @@ namespace IdentityServer.Controllers
{
private
readonly
SignInManager
<
IdentityUser
>
_signInManager
;
private
readonly
UserManager
<
IdentityUser
>
_userManager
;
private
readonly
IIdentityServerInteractionService
_interactionService
;
public
AuthController
(
UserManager
<
IdentityUser
>
userManager
,
SignInManager
<
IdentityUser
>
signInManager
)
SignInManager
<
IdentityUser
>
signInManager
,
IIdentityServerInteractionService
interactionService
)
{
_signInManager
=
signInManager
;
_userManager
=
userManager
;
_interactionService
=
interactionService
;
}
[
HttpGet
]
public
IActionResult
Login
(
string
returnUrl
)
...
...
@@ -26,14 +30,14 @@ namespace IdentityServer.Controllers
return
View
(
new
LoginViewModel
{
ReturnUrl
=
returnUrl
});
}
[
HttpPost
]
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
vm
)
{
//check if model is exsist
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
vm
.
Username
,
vm
.
Password
,
false
,
false
);
if
(
result
.
Succeeded
)
var
result
=
await
_signInManager
.
PasswordSignInAsync
(
vm
.
Username
,
vm
.
Password
,
false
,
false
);
if
(
result
.
IsNotAllowed
)
{
return
Redirect
(
vm
.
ReturnUrl
);
}
...
...
@@ -44,6 +48,22 @@ namespace IdentityServer.Controllers
return
View
();
}
[
HttpGet
]
public
async
Task
<
IActionResult
>
Logout
(
string
logoutId
)
{
await
_signInManager
.
SignOutAsync
();
var
logoutRequest
=
await
_interactionService
.
GetLogoutContextAsync
(
logoutId
);
if
(
string
.
IsNullOrEmpty
(
logoutRequest
.
PostLogoutRedirectUri
))
{
return
RedirectToAction
(
"Index"
,
"Home"
);
}
return
Redirect
(
logoutRequest
.
PostLogoutRedirectUri
);
}
[
HttpGet
]
public
IActionResult
Register
(
string
returnUrl
)
{
...
...
IdentityServer/Startup.cs
View file @
dab5a2ca
...
...
@@ -45,6 +45,7 @@ namespace IdentityServer
{
config
.
Cookie
.
Name
=
"IdentityServer.Cookie"
;
config
.
LoginPath
=
"/Auth/Login"
;
config
.
LogoutPath
=
"/Auth/Logout"
;
});
var
assembly
=
typeof
(
Startup
).
Assembly
.
GetName
().
Name
;
...
...
@@ -59,7 +60,7 @@ namespace IdentityServer
{
options
.
ConfigureDbContext
=
b
=>
b
.
UseSqlServer
(
connectionString
,
sql
=>
sql
.
MigrationsAssembly
(
assembly
));
});
})
.
AddDeveloperSigningCredential
()
;
//.AddInMemoryApiResources(Configuration.GetApis())
//.AddInMemoryIdentityResources(Configuration.GetIdentityResources())
//.AddInMemoryClients(Configuration.GetClients())
...
...
IdentityServer/Views/Auth/Login.cshtml
View file @
dab5a2ca
...
...
@@ -27,7 +27,7 @@
<button type="submit">Sign In</button>
</div>
</form>
@*
<div>
<div>
<a asp-controller="Auth" asp-action="Register"
asp-route-returnUrl="@Model.ReturnUrl">Register</a>
</div>*@
\ No newline at end of file
</div>
\ No newline at end of file
JavascriptClient/wwwroot/main.js
View file @
dab5a2ca
...
...
@@ -3,7 +3,7 @@
authority
:
"https://localhost:44325/"
,
client_id
:
"client_id_js"
,
redirect_uri
:
"https://localhost:44387/Home/SignIn"
,
//post_logout_redirect_uri: "https://localhost:44345
/Home/Index",
post_logout_redirect_uri
:
"https://localhost:44387
/Home/Index"
,
response_type
:
"id_token token"
,
scope
:
"openid rc.scope ApiOne ApiTwo"
};
...
...
@@ -14,9 +14,9 @@ var signIn = function () {
userManager
.
signinRedirect
();
};
//
var signOut = function () {
//
userManager.signoutRedirect();
//
};
var
signOut
=
function
()
{
userManager
.
signoutRedirect
();
};
userManager
.
getUser
().
then
(
user
=>
{
console
.
log
(
"user:"
,
user
);
...
...
MvcClient/Controllers/HomeController.cs
View file @
dab5a2ca
...
...
@@ -25,6 +25,11 @@ namespace MvcClient.Controllers
return
View
();
}
public
IActionResult
Logout
()
{
return
SignOut
(
"Cookie"
,
"oidc"
);
}
[
Authorize
]
public
async
Task
<
IActionResult
>
Secret
()
{
...
...
MvcClient/Startup.cs
View file @
dab5a2ca
...
...
@@ -27,7 +27,7 @@ namespace MvcClient
config
.
SaveTokens
=
true
;
config
.
ResponseType
=
"code"
;
config
.
SignedOutCallbackPath
=
"/Home/Index"
;
//config cookie claim mapping
config
.
ClaimActions
.
DeleteClaim
(
"amr"
);
config
.
ClaimActions
.
MapUniqueJsonKey
(
"ReadaCoding.Grandma"
,
"rc.grandma"
);
...
...
@@ -42,7 +42,7 @@ namespace MvcClient
config
.
Scope
.
Add
(
"offline_access"
);
}
);
});
services
.
AddHttpClient
();
...
...
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