首页 > 解决方案 > 在 ColdFusion 中使用 OneLogin 实现 SAML 时抛出错误

问题描述

作为学习如何在我的 ColdFusion 应用程序中集成 OneLogin SSO 的一部分,我提取了这个 git 存储库 - https://github.com/GiancarloGomez/ColdFusion-OneLogin并在本地设置。但是,在向 OneLogin 发送身份验证请求时,我们收到一条错误消息:“我们很抱歉,但出了点问题。我们已收到有关此问题的通知,我们会尽快查看。

我找不到这个问题的根本原因。感谢您在这方面的及时帮助。

OneLogin 上的配置如下所示。请注意,我将消费者 URL 修改为http://127.0.0.1:8500/coldfusion-onelogin/consume.cfm而不是YouTube中提到的实际格式 ( http://127.0.0.1:8500/coldfusion-onelogin/consume/ )此 git repo 的自述文件中提供的视频。我曾尝试将消费者 URL 格式更改为http://127.0.0.1:8500/coldfusion-onelogin/consume/但我们仍然收到错误消息。

在此处输入图像描述

OneLogin 中的访问选项卡如下所示,

在此处输入图像描述

下面是向 OneLogin 发送身份验证请求的代码。

<cfscript>
  try{

    // used to encode string - chose to use Java version just in case CF did not encode correctly
    // encodeForURL appears to work but to keep the same as the samples from OneLogin I will use the Java reference
    urlEncoder = createObject("java","java.net.URLEncoder");

    // the appSettings object contain application specific settings used by the SAML library
    appSettings = createObject("java","com.onelogin.AppSettings");

    // set the URL of the consume file for this app. The SAML Response will be posted to this URL
    appSettings.setAssertionConsumerServiceUrl(request.company.getConsumeUrl());

    // set the issuer of the authentication request. This would usually be the URL of the issuing web application
    appSettings.setIssuer(request.company.getIssuerUrl());

    // the accSettings object contains settings specific to the users account.
    accSettings = createObject("java","com.onelogin.AccountSettings");

    // The URL at the Identity Provider where to the authentication request should be sent
    accSettings.setIdpSsoTargetUrl("https://app.onelogin.com/saml/signon/" & request.company.getIssuerID());

    // Generate an AuthRequest and send it to the identity provider
    authReq = createObject("java","com.onelogin.saml.AuthRequest").init(appSettings, accSettings);

    // now send to one login
    location ( accSettings.getIdp_sso_target_url() & "?SAMLRequest=" & authReq.getRidOfCRLF(urlEncoder.encode(authReq.getRequest(authReq.base64),"UTF-8")), false);
  }
catch(Any e){
    writeDump(e);
}
</cfscript>

下面是 auth request URL 的格式,

https://app.onelogin.com/saml/signon/[issuerId]?SAMLRequest=[SamlRequest]

我没有在这里提供实际的 URL,因为我不确定是否有人可以篡改它。但请让我们知道是否真的需要解决这个问题。

下面是 SAML 登录页面的屏幕截图,从这里我单击按钮并将身份验证请求发送到 OneLogin。

在此处输入图像描述

此外,在 index.cfm 中,表单操作属性是“/post/”。由于它抛出错误,我不得不用“/coldfusion-onelogin/post.cfm”替换它。这里coldfusion-onelogin是wwwroot下的一个文件夹。ColdFusion 中的任何设置都需要修改,这样如果我们将表单操作属性保持为“/post/”,它就不会抛出任何错误?

标签: javacoldfusionsaml-2.0onelogincoldfusion-2018

解决方案


您需要先从 OneLogin 管理面板注销

https://app.onelogin.com/logout

成功测试演示应用程序。


推荐阅读