Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json Format Hatası #1

Closed
desstannoz opened this issue Sep 22, 2019 · 4 comments
Closed

Json Format Hatası #1

desstannoz opened this issue Sep 22, 2019 · 4 comments

Comments

@desstannoz
Copy link
Contributor

desstannoz commented Sep 22, 2019

Merhaba hocam;
var headerBytes = Encoding.UTF8.GetBytes($"{{'alg':'{HmacAlgorithm.HSA256}', 'typ': 'JWT'}}"); var headerBase = Base64UrlEncoder.Encode(headerBytes);

Kodunda Json formatı yanlış olarak alınıyor.

### Çözüm Kodu:

`var headerJson = JsonConvert.DeserializeObject($"{{'alg':'{HmacAlgorithm.HS256}', 'typ': 'JWT'}}").ToString();

var headerBytes = Encoding.UTF8.GetBytes(headerJson);
var headerBase = Base64UrlEncoder.Encode(headerBytes);`

Bu şekilde Json çıktısı:

{
"alg": "HS256",
"typ": "JWT"
}

haderBase çıktısınıı jwt.io dan decode yaptırdığımızda Header çıktısını görebiliyoruz.

@desstannoz
Copy link
Contributor Author

desstannoz commented Sep 22, 2019

var headerJson = JsonConvert.DeserializeObject($"{{'alg':'{HmacAlgorithm.HS256}', 'typ': 'JWT'}}").ToString();
            var headerBytes = Encoding.UTF8.GetBytes(headerJson);
            var headerBase = Base64UrlEncoder.Encode(headerBytes);

            var payloadBytes =
                Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new JwtToken() { Name = "Kazim Ozkurt" }));
            var payloadBase = Base64UrlEncoder.Encode(payloadBytes);

            var payload = headerBase + "." + payloadBase;

@tarikguney

@tarikguney
Copy link
Owner

@desstannoz Supersin! Sana zahmet PR gonderebilir misin?

@desstannoz
Copy link
Contributor Author

@desstannoz Supersin! Sana zahmet PR gonderebilir misin?

Tabi hocam son yaptıklarınızı da pushlar mısınız acaba?

@desstannoz
Copy link
Contributor Author

desstannoz commented Sep 23, 2019

#3 Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants