Views: 5
通常開發或導入中,免不了需要用某人的帳號登入EIP系統,因此我們其實需要一個可以選擇User,然後選擇後可以登入系統的小工具,這篇文章分享這個工具怎麼做
我僅放在我開發環境的站台中,作為測試用。
官方的SSO文件(請去官方論壇下載)
官方的SSO文件藏在論壇的其中幾篇文章,找不到的可以用這個 連結 ,下載需要有一等一科技的客戶帳號才能進入,如果沒有帳號可以來信跟我索取檔案。
大致步驟
ThirdLoginHelper.dll
放到EIP目錄下的bin中App_Data\Setting.xml
加入參數- 寫頁面
- 加入選人元件
- 加入環境選擇選項
- 產生登入網址,呼叫步驟
ThirdLoginHelper.Encryption.GetUrl();
1. ThirdLoginHelper.dll
放到EIP目錄下的bin
中
這邊請自行解壓縮ThirdLoginHelper.zip
,裡面有檔案
2. App_Data\Setting.xml
加入參數
這邊直接開啟檔案後 搜尋ThirdLogin
,大約在280行
然後我們加入app name
=….那行,其中key
跟iv
請自行產生,可以使用產生器產生就好,name
也請自己命名,整個字串組好如下
<ThirdLogin>
<app name="DevToolDoor" key="Pr5pAsT9jupohu2raho*" iv="swuges8lcR2" expiredSeconds="300" defaultCulture="zh-TW" failUrlFormat="" />
</ThirdLogin>
name
:自訂字串(識別用)key
加密KEYiv
加密IVexpiredSeconds
:連線過期秒數defaultCulture
:預設登入語系failUrlFormate
: 自訂失敗時要跳轉的網址https://example.com/?exption={0}
會傳入exception內容
註:如果想要測試跟正式環境都可以登入,這兩個環境的
Setting.xml
都要改
3. EIP中寫一個登入用頁面
我把頁面新增在CDS\backdoor\default.aspx
我的頁面連結是 http://localhost/UOFTEST/CDS/backdoor/default.aspx
程式碼請自行修改
- 登入網址
- appName
- key
- IV
完成後畫面

程式碼前端 Default.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Master/DefaultMasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CDS_backdoor_Default" %>
<%@ Register Src="~/Common/ChoiceCenter/UC_BtnChoiceOnce.ascx" TagPrefix="uc1" TagName="UC_BtnChoiceOnce" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script>
function copyDoorUrl() {
var doorUrlInput = document.getElementById("<%= DoorUrl.ClientID %>");
doorUrlInput.select();
doorUrlInput.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("已複製連結");
}
</script>
<table class="PopTable">
<tr>
<td>選人</td>
<td>
<uc1:UC_BtnChoiceOnce runat="server" ID="UC_BtnChoiceOnce" ButtonText="選取人員" OnEditButtonOnClick="UC_BtnChoiceOnce_EditButtonOnClick"/>
</td>
</tr>
<tr>
<tr>
<td class="nowrap">
<asp:Label ID="Label1" runat="server" Text="登入帳號"></asp:Label>
</td>
<td>
<asp:TextBox runat="server" ID="Account"></asp:TextBox>
</td>
</tr>
</tr>
<tr>
<tr>
<td class="nowrap">
登入位置
</td>
<td>
<!-- 這裡的 Value 屬性請自行修改成正確的環境 URL -->
<asp:DropDownList ID="ddlLoginLocation" runat="server">
<asp:ListItem Value="https://..../uof/" Text="正式環境"></asp:ListItem>
<asp:ListItem Value="http://...../UOFTEST/" Text="測試環境"></asp:ListItem>
<asp:ListItem Value="http://localhost/uoftest/" Text="開發環境"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</tr>
<tr>
<td></td>
<td><asp:Button runat="server" Text="產生連結" OnClick="DoLogin"/> </td>
</tr>
<tr>
<td></td>
<td><asp:TextBox runat="server" ID="DoorUrl" Width="100%"></asp:TextBox><button type="button" onclick="copyDoorUrl()">複製連結</button></td>
</tr>
</table>
</asp:Content>
程式碼後端 Default.aspx.cs
using Ede.Uof.Utility.Data;
using System;
/// <summary>
/// 登入用後門
/// </summary>
public partial class CDS_backdoor_Default : Ede.Uof.Utility.Page.BasePage
{
private static string ConnectionString = new DatabaseHelper().Command.Connection.ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 選人元件選取人的事件 除錯用
/// </summary>
/// <param name="userSet"></param>
protected void UC_BtnChoiceOnce_EditButtonOnClick(string[] choiceResult)
{
Account.Text = GetAccount(choiceResult[0]);
DoorUrl.Text = string.Empty;
}
/// <summary>
/// 登入按鈕
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DoLogin(object sender, EventArgs e)
{
string appName = "DevToolDoor"; //登入EIP的應用程式名稱
string webUrl = ddlLoginLocation.SelectedValue; //登入EIP的網址設定
string targeturl = "Homepage.aspx"; //登入後導向EIP的首頁
string account = Account.Text; //登入EIP的帳號
string key = "Pr5pAsT9jupohu2raho*";//加解密用的參數 要跟App_Data/Setting.xml裡的設定一樣
string iv = "swuges8lcR2"; //加解密用的參數 要跟App_Data/Setting.xml裡的設定一樣
string url = ThirdLoginHelper.Encryption.GetUrl(appName, webUrl, targeturl, account, key, iv);
DoorUrl.Text = (url);
}
/// <summary>
/// 從EIP資料庫查詢帳號名稱
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
private string GetAccount(string guid)
{
using (var connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
using (var command = new System.Data.SqlClient.SqlCommand(
"SELECT TOP 1 [ACCOUNT] FROM [TB_EB_USER] WHERE [USER_GUID] = @guid",
connection))
{
command.Parameters.AddWithValue("@guid", guid ?? (object)DBNull.Value);
connection.Open();
object result = command.ExecuteScalar();
return result == null || result == DBNull.Value ? null : result.ToString();
}
}
}
0 Comments