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
730545ef
Commit
730545ef
authored
May 30, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add-oidc-client
parent
f52498b3
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
99 additions
and
10 deletions
+99
-10
Startup.cs
ApiOne/Startup.cs
+9
-2
Configuration.cs
IdentityServer/Configuration.cs
+1
-0
Index.cshtml
JavascriptClient/Views/Home/Index.cshtml
+16
-2
SignIn.cshtml
JavascriptClient/Views/Home/SignIn.cshtml
+6
-4
sign-in-callback.js
JavascriptClient/wwwroot/js-old/sign-in-callback.js
+0
-0
sign-in.js
JavascriptClient/wwwroot/js-old/sign-in.js
+0
-2
main.js
JavascriptClient/wwwroot/main.js
+67
-0
No files found.
ApiOne/Startup.cs
View file @
730545ef
...
...
@@ -23,7 +23,14 @@ namespace ApiOne
//config.RequireHttpsMetadata = false;
});
services
.
AddCors
(
config
=>
{
config
.
AddPolicy
(
"AllowAll"
,
p
=>
p
.
AllowAnyOrigin
()
.
AllowAnyMethod
().
AllowAnyHeader
()
);
});
services
.
AddHttpClient
();
//services.AddCors(confg =>
// confg.AddPolicy("AllowAll",
...
...
@@ -41,7 +48,7 @@ namespace ApiOne
app
.
UseDeveloperExceptionPage
();
}
//
app.UseCors("AllowAll");
app
.
UseCors
(
"AllowAll"
);
app
.
UseRouting
();
...
...
IdentityServer/Configuration.cs
View file @
730545ef
...
...
@@ -62,6 +62,7 @@ namespace IdentityServer
ClientId
=
"client_id_js"
,
AllowedGrantTypes
=
GrantTypes
.
Implicit
,
RedirectUris
={
"https://localhost:44387/Home/signin"
},
AllowedCorsOrigins
={
"https://localhost:44387"
},
AllowedScopes
={
IdentityServerConstants
.
StandardScopes
.
OpenId
,
"ApiOne"
,
...
...
JavascriptClient/Views/Home/Index.cshtml
View file @
730545ef
...
...
@@ -5,6 +5,20 @@
<h1>Home Index</h1>
<button onclick="signIn()">SignIn</button>
<script src="~/sign-in.js"></script>
\ No newline at end of file
<div>
<button onclick="signOut()">Sign Out</button>
</div>
<div>
<button onclick="callApi()">Call Api</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.9.1/oidc-client.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="~/main.js"></script>
\ No newline at end of file
JavascriptClient/Views/Home/SignIn.cshtml
View file @
730545ef
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.9.1/oidc-client.min.js"></script>
<script>var userManger = new Oidc.UserManager({
userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
response_mode: "query"
});
<script>
var userManger = new Oidc.UserManager();
//var userManger = new Oidc.UserManager({
// userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
// response_mode: "query"
//});
userManger.signinCallback().then(res => {
console.log(res);
...
...
JavascriptClient/wwwroot/sign-in-callback.js
→
JavascriptClient/wwwroot/
js-old/
sign-in-callback.js
View file @
730545ef
File moved
JavascriptClient/wwwroot/sign-in.js
→
JavascriptClient/wwwroot/
js-old/
sign-in.js
View file @
730545ef
...
...
@@ -20,6 +20,5 @@ var signIn = function () {
"&state="
+
createState
();
var
returnUrl
=
encodeURIComponent
(
authUrl
);
console
.
log
(
returnUrl
);
window
.
location
.
href
=
"https://localhost:44325/Auth/Login?ReturnUrl="
+
returnUrl
;
}
\ No newline at end of file
JavascriptClient/wwwroot/main.js
0 → 100644
View file @
730545ef
var
config
=
{
//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"
};
var
userManager
=
new
Oidc
.
UserManager
(
config
);
var
signIn
=
function
()
{
userManager
.
signinRedirect
();
};
//var signOut = function () {
// userManager.signoutRedirect();
//};
userManager
.
getUser
().
then
(
user
=>
{
console
.
log
(
"user:"
,
user
);
if
(
user
)
{
axios
.
defaults
.
headers
.
common
[
"Authorization"
]
=
"Bearer "
+
user
.
access_token
;
}
});
var
callApi
=
function
()
{
axios
.
get
(
"https://localhost:44340/secret"
)
.
then
(
res
=>
{
console
.
log
(
res
);
});
};
//var refreshing = false;
//axios.interceptors.response.use(
// function (response) { return response; },
// function (error) {
// console.log("axios error:", error.response);
// var axiosConfig = error.response.config;
// //if error response is 401 try to refresh token
// if (error.response.status === 401) {
// console.log("axios error 401");
// // 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);
// });
// }
// }
// return Promise.reject(error);
// });
\ No newline at end of file
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