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
d873090f
Commit
d873090f
authored
May 27, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add access-token-and-id-token
parent
4402f5c6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
5 deletions
+15
-5
SecretController.cs
ApiOne/Controllers/SecretController.cs
+1
-1
Configuration.cs
IdentityServer/Configuration.cs
+1
-1
Program.cs
IdentityServer/Program.cs
+2
-0
HomeController.cs
MvcClient/Controllers/HomeController.cs
+3
-3
Startup.cs
MvcClient/Startup.cs
+8
-0
No files found.
ApiOne/Controllers/SecretController.cs
View file @
d873090f
...
...
@@ -13,7 +13,7 @@ namespace ApiOne.Controllers
[
Authorize
]
public
string
Index
()
{
//
var claims = User.Claims.ToList();
var
claims
=
User
.
Claims
.
ToList
();
return
"secret message from ApiOne"
;
}
}
...
...
IdentityServer/Configuration.cs
View file @
d873090f
...
...
@@ -27,7 +27,7 @@ namespace IdentityServer
new
List
<
ApiResource
>
{
new
ApiResource
(
"ApiOne"
),
new
ApiResource
(
"ApiTwo"
),
new
ApiResource
(
"ApiTwo"
,
new
string
[]{
"rc.api.grandma"
}
),
};
public
static
IEnumerable
<
Client
>
GetClients
()
=>
new
List
<
Client
>
...
...
IdentityServer/Program.cs
View file @
d873090f
...
...
@@ -25,6 +25,8 @@ namespace IdentityServer
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"
))
.
GetAwaiter
().
GetResult
();
}
host
.
Run
();
}
...
...
MvcClient/Controllers/HomeController.cs
View file @
d873090f
...
...
@@ -38,7 +38,7 @@ namespace MvcClient.Controllers
var
result
=
await
GetSecret
(
accessToken
);
await
RefreshAccessToken
();
//
await RefreshAccessToken();
return
View
();
}
...
...
@@ -49,7 +49,7 @@ namespace MvcClient.Controllers
apiClient
.
SetBearerToken
(
accessToken
);
var
response
=
await
apiClient
.
GetAsync
(
"https://localhost:443
37
/secret"
);
var
response
=
await
apiClient
.
GetAsync
(
"https://localhost:443
40
/secret"
);
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
...
...
@@ -59,7 +59,7 @@ namespace MvcClient.Controllers
private
async
Task
RefreshAccessToken
()
{
var
serverClient
=
_httpClientFactory
.
CreateClient
();
var
discoveryDocument
=
await
serverClient
.
GetDiscoveryDocumentAsync
(
"https://localhost:443
0
5/"
);
var
discoveryDocument
=
await
serverClient
.
GetDiscoveryDocumentAsync
(
"https://localhost:443
2
5/"
);
var
accessToken
=
await
HttpContext
.
GetTokenAsync
(
"access_token"
);
var
idToken
=
await
HttpContext
.
GetTokenAsync
(
"id_token"
);
...
...
MvcClient/Startup.cs
View file @
d873090f
...
...
@@ -2,6 +2,7 @@ using System;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
...
...
@@ -27,10 +28,17 @@ namespace MvcClient
config
.
ResponseType
=
"code"
;
//config cookie claim mapping
config
.
ClaimActions
.
DeleteClaim
(
"amr"
);
config
.
ClaimActions
.
MapUniqueJsonKey
(
"ReadaCoding.Grandma"
,
"rc.grandma"
);
//two trips to load claims in to the cookie
config
.
GetClaimsFromUserInfoEndpoint
=
true
;
//configure scope
config
.
Scope
.
Clear
();
config
.
Scope
.
Add
(
"openid"
);
config
.
Scope
.
Add
(
"rc.scope"
);
config
.
Scope
.
Add
(
"ApiOne"
);
config
.
Scope
.
Add
(
"ApiTwo"
);
}
);
...
...
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