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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
8 deletions
+18
-8
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
+5
-5
Startup.cs
MvcClient/Startup.cs
+9
-1
No files found.
ApiOne/Controllers/SecretController.cs
View file @
d873090f
...
@@ -13,7 +13,7 @@ namespace ApiOne.Controllers
...
@@ -13,7 +13,7 @@ namespace ApiOne.Controllers
[
Authorize
]
[
Authorize
]
public
string
Index
()
public
string
Index
()
{
{
//
var claims = User.Claims.ToList();
var
claims
=
User
.
Claims
.
ToList
();
return
"secret message from ApiOne"
;
return
"secret message from ApiOne"
;
}
}
}
}
...
...
IdentityServer/Configuration.cs
View file @
d873090f
...
@@ -27,7 +27,7 @@ namespace IdentityServer
...
@@ -27,7 +27,7 @@ namespace IdentityServer
new
List
<
ApiResource
>
new
List
<
ApiResource
>
{
{
new
ApiResource
(
"ApiOne"
),
new
ApiResource
(
"ApiOne"
),
new
ApiResource
(
"ApiTwo"
),
new
ApiResource
(
"ApiTwo"
,
new
string
[]{
"rc.api.grandma"
}
),
};
};
public
static
IEnumerable
<
Client
>
GetClients
()
=>
public
static
IEnumerable
<
Client
>
GetClients
()
=>
new
List
<
Client
>
new
List
<
Client
>
...
...
IdentityServer/Program.cs
View file @
d873090f
...
@@ -25,6 +25,8 @@ namespace IdentityServer
...
@@ -25,6 +25,8 @@ namespace IdentityServer
userManager
.
CreateAsync
(
user
,
"password"
).
GetAwaiter
().
GetResult
();
userManager
.
CreateAsync
(
user
,
"password"
).
GetAwaiter
().
GetResult
();
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.garndma"
,
"big.cookie"
))
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.garndma"
,
"big.cookie"
))
.
GetAwaiter
().
GetResult
();
.
GetAwaiter
().
GetResult
();
userManager
.
AddClaimAsync
(
user
,
new
Claim
(
"rc.api.garndma"
,
"big..api.cookie"
))
.
GetAwaiter
().
GetResult
();
}
}
host
.
Run
();
host
.
Run
();
}
}
...
...
MvcClient/Controllers/HomeController.cs
View file @
d873090f
...
@@ -38,18 +38,18 @@ namespace MvcClient.Controllers
...
@@ -38,18 +38,18 @@ namespace MvcClient.Controllers
var
result
=
await
GetSecret
(
accessToken
);
var
result
=
await
GetSecret
(
accessToken
);
await
RefreshAccessToken
();
//
await RefreshAccessToken();
return
View
();
return
View
();
}
}
public
async
Task
<
string
>
GetSecret
(
string
accessToken
)
public
async
Task
<
string
>
GetSecret
(
string
accessToken
)
{
{
var
apiClient
=
_httpClientFactory
.
CreateClient
();
var
apiClient
=
_httpClientFactory
.
CreateClient
();
apiClient
.
SetBearerToken
(
accessToken
);
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
();
var
content
=
await
response
.
Content
.
ReadAsStringAsync
();
...
@@ -59,8 +59,8 @@ namespace MvcClient.Controllers
...
@@ -59,8 +59,8 @@ namespace MvcClient.Controllers
private
async
Task
RefreshAccessToken
()
private
async
Task
RefreshAccessToken
()
{
{
var
serverClient
=
_httpClientFactory
.
CreateClient
();
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
accessToken
=
await
HttpContext
.
GetTokenAsync
(
"access_token"
);
var
idToken
=
await
HttpContext
.
GetTokenAsync
(
"id_token"
);
var
idToken
=
await
HttpContext
.
GetTokenAsync
(
"id_token"
);
var
refreshToken
=
await
HttpContext
.
GetTokenAsync
(
"refresh_token"
);
var
refreshToken
=
await
HttpContext
.
GetTokenAsync
(
"refresh_token"
);
...
...
MvcClient/Startup.cs
View file @
d873090f
...
@@ -2,6 +2,7 @@ using System;
...
@@ -2,6 +2,7 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http
;
...
@@ -27,12 +28,19 @@ namespace MvcClient
...
@@ -27,12 +28,19 @@ namespace MvcClient
config
.
ResponseType
=
"code"
;
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
//two trips to load claims in to the cookie
config
.
GetClaimsFromUserInfoEndpoint
=
true
;
config
.
GetClaimsFromUserInfoEndpoint
=
true
;
//configure scope
//configure scope
config
.
Scope
.
Clear
();
config
.
Scope
.
Add
(
"openid"
);
config
.
Scope
.
Add
(
"rc.scope"
);
config
.
Scope
.
Add
(
"rc.scope"
);
config
.
Scope
.
Add
(
"ApiOne"
);
config
.
Scope
.
Add
(
"ApiTwo"
);
}
);
}
);
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