From 3b0c275fbcbfdfc74d54012e691a318352f30d1e Mon Sep 17 00:00:00 2001 From: heromyth Date: Thu, 23 Jul 2020 16:09:21 +0800 Subject: [PATCH] Add JwtRegisteredClaimNames --- source/jwt/JwtRegisteredClaimNames.d | 113 +++++++++++++++++++++++++++ source/jwt/jwt.d | 6 +- source/jwt/package.d | 1 + 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 source/jwt/JwtRegisteredClaimNames.d diff --git a/source/jwt/JwtRegisteredClaimNames.d b/source/jwt/JwtRegisteredClaimNames.d new file mode 100644 index 0000000..e841a52 --- /dev/null +++ b/source/jwt/JwtRegisteredClaimNames.d @@ -0,0 +1,113 @@ +module jwt.JwtRegisteredClaimNames; + +// +// Summary: +// List of registered claims from different sources http://tools.ietf.org/html/rfc7519#section-4 +// http://openid.net/specs/openid-connect-core-1_0.html#IDToken +struct JwtRegisteredClaimNames { + enum string Actort = "actort"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-5 + enum string Typ = "typ"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Sub = "sub"; + // + // Summary: + // http://openid.net/specs/openid-connect-frontchannel-1_0.html#OPLogout + enum string Sid = "sid"; + enum string Prn = "prn"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Nbf = "nbf"; + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest + enum string Nonce = "nonce"; + enum string NameId = "nameid"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Jti = "jti"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Iss = "iss"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Iat = "iat"; + + /** + * End-User's full name in displayable form including all name parts, + * possibly including titles and suffixes, ordered according to the End-User's locale and preferences. + */ + enum string Name = "name"; + + enum string Nickname = "nickname"; + + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims + enum string GivenName = "given_name"; + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims + enum string FamilyName = "family_name"; + + enum string MiddleName = "middle_name"; + + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims + enum string Gender = "gender"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Exp = "exp"; + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims + enum string Email = "email"; + // + // Summary: + // http://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken + enum string AtHash = "at_hash"; + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#HybridIDToken + enum string CHash = "c_hash"; + // + // Summary: + // https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims + enum string Birthdate = "birthdate"; + // + // Summary: + // http://openid.net/specs/openid-connect-core-1_0.html#IDToken + enum string Azp = "azp"; + // + // Summary: + // http://openid.net/specs/openid-connect-core-1_0.html#IDToken + enum string AuthTime = "auth_time"; + // + // Summary: + // http://tools.ietf.org/html/rfc7519#section-4 + enum string Aud = "aud"; + // + // Summary: + // http://openid.net/specs/openid-connect-core-1_0.html#IDToken + enum string Amr = "amr"; + // + // Summary: + // http://openid.net/specs/openid-connect-core-1_0.html#IDToken + enum string Acr = "acr"; + enum string UniqueName = "unique_name"; + enum string Website = "website"; + + enum string PhoneNumber = "phone_number"; + + enum string Address = "address"; +} diff --git a/source/jwt/jwt.d b/source/jwt/jwt.d index 83680ac..d25de6e 100644 --- a/source/jwt/jwt.d +++ b/source/jwt/jwt.d @@ -76,7 +76,11 @@ public: } void set(T)(string name, T data) { - this.data.object[name] = JSONValue(data); + static if(is(T == JSONValue)) { + this.data.object[name] = data; + } else { + this.data.object[name] = JSONValue(data); + } } /** diff --git a/source/jwt/package.d b/source/jwt/package.d index cf18d74..bebb2e1 100644 --- a/source/jwt/package.d +++ b/source/jwt/package.d @@ -1,5 +1,6 @@ module jwt; +public import jwt.JwtRegisteredClaimNames; public import jwt.algorithms; public import jwt.exceptions; public import jwt.jwt; \ No newline at end of file