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
f61b6448
Commit
f61b6448
authored
May 31, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config-persistance-claims-refreshing-imolicit-flow
parent
730545ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
37 deletions
+39
-37
Configuration.cs
IdentityServer/Configuration.cs
+6
-0
Program.cs
IdentityServer/Program.cs
+3
-2
SignIn.cshtml
JavascriptClient/Views/Home/SignIn.cshtml
+2
-5
main.js
JavascriptClient/wwwroot/main.js
+28
-30
No files found.
IdentityServer/Configuration.cs
View file @
f61b6448
...
...
@@ -60,13 +60,19 @@ namespace IdentityServer
new
Client
{
ClientId
=
"client_id_js"
,
AllowedGrantTypes
=
GrantTypes
.
Implicit
,
RedirectUris
={
"https://localhost:44387/Home/signin"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
AllowedScopes
={
IdentityServerConstants
.
StandardScopes
.
OpenId
,
"ApiOne"
,
"ApiTwo"
,
"rc.scope"
,
},
AccessTokenLifetime
=
1
,
AllowAccessTokensViaBrowser
=
true
,
RequireConsent
=
false
...
...
IdentityServer/Program.cs
View file @
f61b6448
...
...
@@ -21,11 +21,12 @@ namespace IdentityServer
{
var
userManager
=
scope
.
ServiceProvider
.
GetRequiredService
<
UserManager
<
IdentityUser
>>();
var
user
=
new
IdentityUser
(
"
alan
"
);
var
user
=
new
IdentityUser
(
"
bob
"
);
userManager
.
CreateAsync
(
user
,
"password"
).
GetAwaiter
().
GetResult
();
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.garndma"
,
"big.cookie"
))
.
GetAwaiter
().
GetResult
();
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.api.garndma"
,
"big..api.cookie"
))
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.api.garndma"
,
"big.api.cookie"
))
.
GetAwaiter
().
GetResult
();
}
host
.
Run
();
...
...
JavascriptClient/Views/Home/SignIn.cshtml
View file @
f61b6448
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.9.1/oidc-client.min.js"></script>
<script>
var userManger = new Oidc.UserManager();
//var userManger = new Oidc.UserManager({
// userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
// response_mode: "query"
//});
//var userManger = new Oidc.UserManager();
var userManger = new Oidc.UserManager({userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }) });
userManger.signinCallback().then(res => {
console.log(res);
...
...
JavascriptClient/wwwroot/main.js
View file @
f61b6448
var
config
=
{
//
userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
userStore
:
new
Oidc
.
WebStorageStateStore
({
store
:
window
.
localStorage
}),
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",
response_type
:
"id_token token"
,
scope
:
"openid
ApiOne
"
scope
:
"openid
rc.scope ApiOne ApiTwo
"
};
var
userManager
=
new
Oidc
.
UserManager
(
config
);
...
...
@@ -18,7 +18,7 @@ var signIn = function () {
// userManager.signoutRedirect();
//};
userManager
.
getUser
().
then
(
user
=>
{
userManager
.
getUser
().
then
(
user
=>
{
console
.
log
(
"user:"
,
user
);
if
(
user
)
{
axios
.
defaults
.
headers
.
common
[
"Authorization"
]
=
"Bearer "
+
user
.
access_token
;
...
...
@@ -34,33 +34,32 @@ var callApi = function () {
//var refreshing = false;
//axios.interceptors.response.use(
// function (response) { return response; },
// function (error) {
// console.log("axios error:", error.response);
var
axiosConfig
=
error
.
response
.
config
;
// var axiosConfig = error.response.config;
axios
.
interceptors
.
response
.
use
(
function
(
response
)
{
return
response
;
},
function
(
error
)
{
console
.
log
(
"axios error:"
,
error
.
response
);
return
Promise
.
reject
(
error
);
var
axiosConfig
=
error
.
response
.
config
;
//if error response is 401 try to refresh token
if
(
error
.
response
.
status
===
401
)
{
// //if error response is 401 try to refresh token
// if (error.response.status === 401
) {
// console.log("axios error 401")
;
console
.
log
(
"axios error 401"
);
if
(
!
refreshing
)
{
refreshing
=
true
;
// // if already refreshing don't make another request
// if (!refreshing) {
// console.log("starting token refresh");
// refreshing = true;
//do the refresh
return
userManager
.
signinSilent
().
then
(
user
=>
{
console
.
log
(
"new user:"
,
user
);
//update the http request and client
axios
.
defaults
.
headers
.
common
[
"Authorization"
]
=
"Bearer "
+
user
.
access_token
;
axiosConfig
.
headers
[
"Authorization"
]
=
"Bearer "
+
user
.
access_token
;
//retry the http request
return
axios
(
axiosConfig
);
});
}
// // do the refresh
// return userManager.signinSilent().then(user => {
// console.log("new user:", user);
// //update the http request and client
// axios.defaults.headers.common["Authorization"] = "Bearer " + user.access_token;
// axiosConfig.headers["Authorization"] = "Bearer " + user.access_token;
// //retry the http request
// return axios(axiosConfig);
// });
// }
// }
// return Promise.reject(error);
// });
\ No newline at end of file
}
return
Promise
.
reject
(
error
);
});
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