Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
Project
Project
Details
Activity
Releases
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
黄奎
Education
Commits
fdb7fc8f
Commit
fdb7fc8f
authored
Oct 10, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
9185416c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
ApiFilterAttribute.cs
Edu.WebApi/Filter/ApiFilterAttribute.cs
+1
-1
WebApiTokenHelper.cs
Edu.WebApi/Helper/WebApiTokenHelper.cs
+10
-9
No files found.
Edu.WebApi/Filter/ApiFilterAttribute.cs
View file @
fdb7fc8f
...
...
@@ -102,7 +102,7 @@ namespace Edu.WebApi.Filter
}
catch
(
Exception
ex
)
{
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
string
.
Format
(
"DoApiMonitorLog:{0}"
,
responseData
));
Common
.
Plugin
.
LogHelper
.
Write
(
ex
,
string
.
Format
(
"DoApiMonitorLog:{0}"
,
responseData
));
}
token
=
headers
[
"token"
].
ToString
();
}
...
...
Edu.WebApi/Helper/WebApiTokenHelper.cs
View file @
fdb7fc8f
...
...
@@ -16,8 +16,8 @@ namespace Edu.WebApi.Helper
/// <summary>
/// 生成Token
/// </summary>
/// <param name="uid"></param>
/// <param name="requestFromEnum"></param>
/// <param name="uid">
加密字符串
</param>
/// <param name="requestFromEnum">
来源
</param>
/// <returns></returns>
public
static
string
CreateToken
(
string
uid
,
Common
.
Enum
.
ApiRequestFromEnum
requestFromEnum
)
{
...
...
@@ -26,12 +26,12 @@ namespace Edu.WebApi.Helper
var
now
=
provider
.
GetNow
().
AddMinutes
(-
1
);
var
unixEpoch
=
new
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
.
Utc
);
var
secondsSinceEpoch
=
Math
.
Round
((
now
-
unixEpoch
).
TotalSeconds
);
var
payload
=
new
Dictionary
<
string
,
object
>
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Common
.
Config
.
JwtExpirTime
},
{
Common
.
GlobalKey
.
JWT_User_Key
,
userInfo
}
};
var
payload
=
new
Dictionary
<
string
,
object
>
()
{
{
"iat"
,
secondsSinceEpoch
},
{
"exp"
,
secondsSinceEpoch
+
Common
.
Config
.
JwtExpirTime
},
{
Common
.
GlobalKey
.
JWT_User_Key
,
userInfo
}
};
IJwtAlgorithm
algorithm
=
new
HMACSHA256Algorithm
();
IJsonSerializer
serializer
=
new
JsonNetSerializer
();
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
...
...
@@ -54,7 +54,8 @@ namespace Edu.WebApi.Helper
IBase64UrlEncoder
urlEncoder
=
new
JwtBase64UrlEncoder
();
IJwtDecoder
decoder
=
new
JwtDecoder
(
serializer
,
validator
,
urlEncoder
);
string
secret
=
Common
.
Config
.
JwtSecretKey
;
var
json
=
decoder
.
Decode
(
token
,
secret
,
verify
:
true
);
//token为之前生成的字符串
//token为之前生成的字符串
var
json
=
decoder
.
Decode
(
token
,
secret
,
verify
:
true
);
JObject
jwtJson
=
JObject
.
Parse
(
json
);
return
jwtJson
;
}
...
...
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