OneDrive / onedrive-sdk-dotnet-msa-auth-adapter

Other
25 stars 22 forks source link

Can't i use msaAuthProvider.AuthenticateUserAsync() in .Net Core 3.1 #70

Open muscankaraoglu opened 4 years ago

muscankaraoglu commented 4 years ago

image

As you can see, when i came on await msaAuthProvider.AuthenticateUserAsync(); line it throws this exception. I couldn't find any answer for this issue in .net core. Is this supports .net core 3.1?

Can anyone help me?

Mogikan commented 4 years ago

Seem like it is a dead repository and no one cares to reply. I wonder how to contact their management staff.

muscankaraoglu commented 4 years ago

I am also curious, but I solved the problem as follows; I don't use the OneDrive API anymore :)

Mogikan commented 4 years ago

@muscankaraoglu you need to build it against .net core 3.1. Since Microsoft Graph Core does not support RefreshToken you need to remove corresponding code, but only in adal and business code, not in msaAuthProvider.

chrisgriffis commented 2 years ago

I am also curious, but I solved the problem as follows; I don't use the OneDrive API anymore :)

the problem is here: https://github.com/OneDrive/onedrive-sdk-dotnet-msa-auth-adapter/blob/a7b4696e7a0451caa6ff4b7c2c39628846c45c5a/src/OneDrive.Sdk.Authentication.Common/OAuthHelper.cs#L289

the problem is that some json vals in response (like ttl, for example) are pure numeric and not strings, and so deserialize is throwing when it tries to interp the first num it sees as a string.

the workaround is o provide your own serializer that correctly parses the string as Json, and then converts it to the type param:

        public class MySer : ISerializer
        {
            public T DeserializeObject<T>(System.IO.Stream stream)
            {
                return DeserializeObject<T>(new System.IO.StreamReader(stream).ReadToEnd());
            }

            public T DeserializeObject<T>(string inputString)
            {
                var j = JObject.Parse(inputString);
                return j.ToObject<T>();
            }

            public string SerializeObject(object serializeableObject)
            {
                throw new NotImplementedException();
            }
        }
Mogikan commented 2 years ago

I am also curious, but I solved the problem as follows; I don't use the OneDrive API anymore :)

the problem is here:

https://github.com/OneDrive/onedrive-sdk-dotnet-msa-auth-adapter/blob/a7b4696e7a0451caa6ff4b7c2c39628846c45c5a/src/OneDrive.Sdk.Authentication.Common/OAuthHelper.cs#L289

the problem is that some json vals in response (like ttl, for example) are pure numeric and not strings, and so deserialize is throwing when it tries to interp the first num it sees as a string.

the workaround is o provide your own serializer that correctly parses the string as Json, and then converts it to the type param:

        public class MySer : ISerializer
        {
            public T DeserializeObject<T>(System.IO.Stream stream)
            {
                return DeserializeObject<T>(new System.IO.StreamReader(stream).ReadToEnd());
            }

            public T DeserializeObject<T>(string inputString)
            {
                var j = JObject.Parse(inputString);
                return j.ToObject<T>();
            }

            public string SerializeObject(object serializeableObject)
            {
                throw new NotImplementedException();
            }
        }

I fixed it in OAuthHelper.cs Instead of var responseValues = httpProvider.Serializer.DeserializeObject<IDictionary<string, string>>( responseStream); I use: var rawValues = httpProvider.Serializer.DeserializeObject<Dictionary<string, object>>(responseStream); var responseValues = rawValues.ToDictionary(item => item.Key, item => item.Value.ToString());