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
...
@@ -45,6 +45,7 @@ namespace IdentityServer
ClientSecrets
={
new
Secret
(
"client_secret_mvc"
.
ToSha256
())},
ClientSecrets
={
new
Secret
(
"client_secret_mvc"
.
ToSha256
())},
AllowedGrantTypes
=
GrantTypes
.
Code
,
AllowedGrantTypes
=
GrantTypes
.
Code
,
RedirectUris
={
"https://localhost:44349/signin-oidc"
},
RedirectUris
={
"https://localhost:44349/signin-oidc"
},
PostLogoutRedirectUris
={
"https://localhost:44349/Home/Index"
},
AllowedScopes
={
AllowedScopes
={
"ApiOne"
,
"ApiOne"
,
"ApiTwo"
,
"ApiTwo"
,
...
@@ -64,7 +65,8 @@ namespace IdentityServer
...
@@ -64,7 +65,8 @@ namespace IdentityServer
AllowedGrantTypes
=
GrantTypes
.
Implicit
,
AllowedGrantTypes
=
GrantTypes
.
Implicit
,
RedirectUris
={
"https://localhost:44387/Home/signin"
},
RedirectUris
={
"https://localhost:44387/Home/signin"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
PostLogoutRedirectUris
={
"https://localhost:44387/Home/Idex"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
AllowedScopes
={
AllowedScopes
={
IdentityServerConstants
.
StandardScopes
.
OpenId
,
IdentityServerConstants
.
StandardScopes
.
OpenId
,
...
...
IdentityServer/Controllers/AuthController.cs
View file @
dab5a2ca
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
...
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
IdentityServer.ViewModels
;
using
IdentityServer.ViewModels
;
using
IdentityServer4.Services
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
...
@@ -12,13 +13,16 @@ namespace IdentityServer.Controllers
...
@@ -12,13 +13,16 @@ namespace IdentityServer.Controllers
{
{
private
readonly
SignInManager
<
IdentityUser
>
_signInManager
;
private
readonly
SignInManager
<
IdentityUser
>
_signInManager
;
private
readonly
UserManager
<
IdentityUser
>
_userManager
;
private
readonly
UserManager
<
IdentityUser
>
_userManager
;
private
readonly
IIdentityServerInteractionService
_interactionService
;
public
AuthController
(
public
AuthController
(
UserManager
<
IdentityUser
>
userManager
,
UserManager
<
IdentityUser
>
userManager
,
SignInManager
<
IdentityUser
>
signInManager
)
SignInManager
<
IdentityUser
>
signInManager
,
IIdentityServerInteractionService
interactionService
)
{
{
_signInManager
=
signInManager
;
_signInManager
=
signInManager
;
_userManager
=
userManager
;
_userManager
=
userManager
;
_interactionService
=
interactionService
;
}
}
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Login
(
string
returnUrl
)
public
IActionResult
Login
(
string
returnUrl
)
...
@@ -26,14 +30,14 @@ namespace IdentityServer.Controllers
...
@@ -26,14 +30,14 @@ namespace IdentityServer.Controllers
return
View
(
new
LoginViewModel
{
ReturnUrl
=
returnUrl
});
return
View
(
new
LoginViewModel
{
ReturnUrl
=
returnUrl
});
}
}
[
HttpPost
]
[
HttpPost
]
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
vm
)
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
vm
)
{
{
//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
);
}
}
...
@@ -44,6 +48,22 @@ namespace IdentityServer.Controllers
...
@@ -44,6 +48,22 @@ namespace IdentityServer.Controllers
return
View
();
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
]
[
HttpGet
]
public
IActionResult
Register
(
string
returnUrl
)
public
IActionResult
Register
(
string
returnUrl
)
{
{
...
...
IdentityServer/Startup.cs
View file @
dab5a2ca
...
@@ -45,6 +45,7 @@ namespace IdentityServer
...
@@ -45,6 +45,7 @@ namespace IdentityServer
{
{
config
.
Cookie
.
Name
=
"IdentityServer.Cookie"
;
config
.
Cookie
.
Name
=
"IdentityServer.Cookie"
;
config
.
LoginPath
=
"/Auth/Login"
;
config
.
LoginPath
=
"/Auth/Login"
;
config
.
LogoutPath
=
"/Auth/Logout"
;
});
});
var
assembly
=
typeof
(
Startup
).
Assembly
.
GetName
().
Name
;
var
assembly
=
typeof
(
Startup
).
Assembly
.
GetName
().
Name
;
...
@@ -59,7 +60,7 @@ namespace IdentityServer
...
@@ -59,7 +60,7 @@ namespace IdentityServer
{
{
options
.
ConfigureDbContext
=
b
=>
b
.
UseSqlServer
(
connectionString
,
options
.
ConfigureDbContext
=
b
=>
b
.
UseSqlServer
(
connectionString
,
sql
=>
sql
.
MigrationsAssembly
(
assembly
));
sql
=>
sql
.
MigrationsAssembly
(
assembly
));
});
})
.
AddDeveloperSigningCredential
()
;
//.AddInMemoryApiResources(Configuration.GetApis())
//.AddInMemoryApiResources(Configuration.GetApis())
//.AddInMemoryIdentityResources(Configuration.GetIdentityResources())
//.AddInMemoryIdentityResources(Configuration.GetIdentityResources())
//.AddInMemoryClients(Configuration.GetClients())
//.AddInMemoryClients(Configuration.GetClients())
...
...
IdentityServer/Views/Auth/Login.cshtml
View file @
dab5a2ca
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
<button type="submit">Sign In</button>
<button type="submit">Sign In</button>
</div>
</div>
</form>
</form>
@*
<div>
<div>
<a asp-controller="Auth" asp-action="Register"
<a asp-controller="Auth" asp-action="Register"
asp-route-returnUrl="@Model.ReturnUrl">Register</a>
asp-route-returnUrl="@Model.ReturnUrl">Register</a>
</div>*@
</div>
\ No newline at end of file
\ No newline at end of file
JavascriptClient/wwwroot/main.js
View file @
dab5a2ca
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
authority
:
"https://localhost:44325/"
,
authority
:
"https://localhost:44325/"
,
client_id
:
"client_id_js"
,
client_id
:
"client_id_js"
,
redirect_uri
:
"https://localhost:44387/Home/SignIn"
,
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"
,
response_type
:
"id_token token"
,
scope
:
"openid rc.scope ApiOne ApiTwo"
scope
:
"openid rc.scope ApiOne ApiTwo"
};
};
...
@@ -14,9 +14,9 @@ var signIn = function () {
...
@@ -14,9 +14,9 @@ var signIn = function () {
userManager
.
signinRedirect
();
userManager
.
signinRedirect
();
};
};
//
var signOut = function () {
var
signOut
=
function
()
{
//
userManager.signoutRedirect();
userManager
.
signoutRedirect
();
//
};
};
userManager
.
getUser
().
then
(
user
=>
{
userManager
.
getUser
().
then
(
user
=>
{
console
.
log
(
"user:"
,
user
);
console
.
log
(
"user:"
,
user
);
...
...
MvcClient/Controllers/HomeController.cs
View file @
dab5a2ca
...
@@ -25,6 +25,11 @@ namespace MvcClient.Controllers
...
@@ -25,6 +25,11 @@ namespace MvcClient.Controllers
return
View
();
return
View
();
}
}
public
IActionResult
Logout
()
{
return
SignOut
(
"Cookie"
,
"oidc"
);
}
[
Authorize
]
[
Authorize
]
public
async
Task
<
IActionResult
>
Secret
()
public
async
Task
<
IActionResult
>
Secret
()
{
{
...
...
MvcClient/Startup.cs
View file @
dab5a2ca
...
@@ -27,7 +27,7 @@ namespace MvcClient
...
@@ -27,7 +27,7 @@ namespace MvcClient
config
.
SaveTokens
=
true
;
config
.
SaveTokens
=
true
;
config
.
ResponseType
=
"code"
;
config
.
ResponseType
=
"code"
;
config
.
SignedOutCallbackPath
=
"/Home/Index"
;
//config cookie claim mapping
//config cookie claim mapping
config
.
ClaimActions
.
DeleteClaim
(
"amr"
);
config
.
ClaimActions
.
DeleteClaim
(
"amr"
);
config
.
ClaimActions
.
MapUniqueJsonKey
(
"ReadaCoding.Grandma"
,
"rc.grandma"
);
config
.
ClaimActions
.
MapUniqueJsonKey
(
"ReadaCoding.Grandma"
,
"rc.grandma"
);
...
@@ -42,7 +42,7 @@ namespace MvcClient
...
@@ -42,7 +42,7 @@ namespace MvcClient
config
.
Scope
.
Add
(
"offline_access"
);
config
.
Scope
.
Add
(
"offline_access"
);
}
);
});
services
.
AddHttpClient
();
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