/// <summary> /// Method that sends authentication request to the OP. /// </summary> /// <param name="AuthenticateUrl">The URL to be used for the authentication request.</param> /// <param name="RequestMessage">The reuqest message to be sent to the OP.</param> /// <param name="Certificate">The certificate to be used, in case of a self-issued authentication.</param> /// <returns>The authentication response from the OP.</returns> public OIDCAuthImplicitResponseMessage Authenticate(string AuthenticateUrl, OIDCAuthorizationRequestMessage RequestMessage, X509Certificate2 Certificate = null) { if (new Uri(AuthenticateUrl).Scheme == "openid") { // we are dealing with a Self-Issued OpenID provider Dictionary<string, object> response = PerformSelfIssuedAuthentication(RequestMessage, Certificate); OIDCAuthImplicitResponseMessage responseMessage = new OIDCAuthImplicitResponseMessage(); responseMessage.DeserializeFromDictionary(response); return responseMessage; } else { string login_url = AuthenticateUrl + "?" + RequestMessage.SerializeToQueryString(); WebOperations.GetUrlContent(WebRequest.Create(login_url)); return null; } }
/// <summary> /// Method called toparse an authentication implicit response from OP. /// </summary> /// <param name="queryString">The string reprsenting the authentication response provided /// by the OP.</param> /// <param name="scope">(optional) Eventual scope used for the call to be used for verification.</param> /// <param name="state">(optional) Eventual state used for the call to be used for verification.</param> /// <returns>A validated message containing answer frop OP.</returns> public OIDCAuthImplicitResponseMessage ParseAuthImplicitResponse(string queryString, List<MessageScope> scope = null, string state = null) { OIDCAuthImplicitResponseMessage responseMessage = new OIDCAuthImplicitResponseMessage(); try { responseMessage.DeserializeFromQueryString(queryString); } catch (OIDCException) { OIDCResponseError error = new OIDCResponseError(); error.DeserializeFromQueryString(queryString); throw new OIDCException("Error while parsing authorization response: " + error.Error + "\n" + error.ErrorDescription); } if (state != null && responseMessage.State != state) { throw new OIDCException("Error with authentication answer, wrong state."); } return responseMessage; }