mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
feat(csharp): add jwt token lifetime from config
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
# Change Log
|
||||
|
||||
- csharp: jwt token lifetime from config
|
||||
- golang: jwt token lifetime from config
|
||||
|
||||
## 1.13.0
|
||||
|
||||
@ -20,6 +20,7 @@ using JWT;
|
||||
using JWT.Algorithms;
|
||||
using JWT.Builder;
|
||||
using JWT.Serializers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Configuration;
|
||||
|
||||
@ -28,6 +29,7 @@ namespace OnlineEditorsExample
|
||||
public static class JwtManager
|
||||
{
|
||||
private static readonly string Secret;
|
||||
private static readonly int ExpiresIn;
|
||||
public static readonly bool Enabled;
|
||||
public static readonly bool SignatureUseForRequest;
|
||||
|
||||
@ -35,12 +37,19 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
Secret = WebConfigurationManager.AppSettings["files.docservice.secret"] ?? ""; // get token secret from the config parameters
|
||||
Enabled = !string.IsNullOrEmpty(Secret); // check if the token is enabled
|
||||
ExpiresIn = int.Parse(WebConfigurationManager.AppSettings["files.docservice.token.expires-in"]);
|
||||
SignatureUseForRequest = bool.Parse(WebConfigurationManager.AppSettings["files.docservice.token.useforrequest"]);
|
||||
}
|
||||
|
||||
// encode a payload object into a token using a secret key
|
||||
public static string Encode(IDictionary<string, object> payload)
|
||||
{
|
||||
var now = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
var expires = now + ExpiresIn * 60;
|
||||
|
||||
payload["iat"] = now;
|
||||
payload["exp"] = expires;
|
||||
|
||||
var encoder = new JwtEncoder(new HMACSHA256Algorithm(),
|
||||
new JsonNetSerializer(),
|
||||
new JwtBase64UrlEncoder());
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.token.useforrequest" value="true" />
|
||||
<add key="files.docservice.token.expires-in" value="5"/>
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|sq-AL:Albanian (Albania)|ar:Arabic|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|cs:Czech|da:Danish|nl:Dutch|en-GB:English (United Kingdom)|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|he-IL:Hebrew (Israel)|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sr-Cyrl-RS:Serbian (Cyrillic)|sr-Latn-RS:Serbian (Latin)|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA: Test Language"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user