public static IdToken Parse(string idToken) { if (string.IsNullOrEmpty(idToken)) { return(null); } IdToken idTokenBody = null; string[] idTokenSegments = idToken.Split(new[] { '.' }); if (idTokenSegments.Length < 2) { throw new MsalClientException( MsalError.InvalidJwtError, MsalErrorMessage.IDTokenMustHaveTwoParts); } try { byte[] idTokenBytes = Base64UrlHelpers.DecodeToBytes(idTokenSegments[1]); idTokenBody = JsonHelper.DeserializeFromJson <IdToken>(idTokenBytes); } catch (JsonException exc) { throw new MsalClientException( MsalError.JsonParseError, MsalErrorMessage.FailedToParseIDToken, exc); } return(idTokenBody); }
public static IdToken Parse(string idToken) { if (string.IsNullOrEmpty(idToken)) { return(null); } IdToken idTokenBody = null; string[] idTokenSegments = idToken.Split(new[] { '.' }); if (idTokenSegments.Length < 2) { throw new MsalClientException(MsalClientException.InvalidJwtError, "ID Token must contain at least 2 parts."); } try { byte[] idTokenBytes = Base64UrlHelpers.DecodeToBytes(idTokenSegments[1]); using (var stream = new MemoryStream(idTokenBytes)) { var serializer = new DataContractJsonSerializer(typeof(IdToken)); idTokenBody = (IdToken)serializer.ReadObject(stream); } } catch (Exception exc) { throw new MsalClientException(MsalClientException.JsonParseError, "Failed to parse the returned id token.", exc); } return(idTokenBody); }
public static ClientInfo CreateFromJson(string clientInfo) { if (string.IsNullOrEmpty(clientInfo)) { throw new MsalClientException(MsalClientException.JsonParseError, "client info is null"); } try { return(JsonHelper.DeserializeFromJson <ClientInfo>(Base64UrlHelpers.DecodeToBytes(clientInfo))); } catch (Exception exc) { throw new MsalClientException(MsalClientException.JsonParseError, "Failed to parse the returned client info.", exc); } }