Embed Apps
These code samples illustrate how to use the Get apps to embed for a user API with ASP.net and C#, with and without remote authorization.
Embedding Apps Using C# and ASP.NET
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/
DTD/
xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
// Configuration setting from OneLogin
string embedToken = "xfe5x54c3540xxxx56165bx92xxxe62x042exx23";
// Data about the current user from session etc. (sample data)
string email = "user@mycompany.com";
string url = "https://app.onelogin.com/client/apps/embed2?token=" + embedToken +
"&email=" + email;
// Retrieve XML document from OneLogin
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream stream = wc.OpenRead(url);
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(stream);
stream.Close();
repeater1.DataSource = ds;
repeater1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>OneLogin embedding demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="repeater1" runat="server">
<ItemTemplate>
<asp:HyperLink NavigateUrl='<%# "https://app.onelogin.com/client/apps/
launch/" +
DataBinder.Eval(Container.DataItem, "id") %>' runat="server">
<asp:Image ImageUrl='<%# DataBinder.Eval(Container.DataItem,
"icon") %>'
runat="server" />
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</asp:HyperLink>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
<div>
<asp:Label ID="lbl" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Embedding Apps with Remote Authorization Using C# and ASP.NET
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/
DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
// Configuration setting from OneLogin
string embedToken = "xfe5x54c3540xxxx56165bx92xxxe62x042exx23";
// Data about the current user from session etc. (sample data)
string email = "user@mycompany.com";
string url = "https://app.onelogin.com/client/apps/embed2?token=" + embedToken +
"&email=" + email;
// Retrieve XML document from OneLogin
System.Net.WebClient wc = new System.Net.WebClient();
System.IO.Stream stream = wc.OpenRead(url);
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(stream);
stream.Close();
repeater1.DataSource = ds;
repeater1.DataBind();
}
void App_OnClick(object sender, CommandEventArgs e)
{
// Configuration settings from OneLogin
string remoteAuthToken = "xx8038xf0dx368ed8e5d18x8f16d8b4e25f2b311";
string accountId = "1970";
// Data about the current user from session etc. (sample data)
string email = "christian@onelog.in";
string firstname = "Christian";
string lastname = "Pedersen";
string loginId = e.CommandArgument.ToString();
// Calculate a UNIX-style UTC timestamp
TimeSpan ts = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0));
string unixTime = System.Math.Round(ts.TotalSeconds,0).ToString();
// Create a MD5 digest (HEX) of the payload
string payload = firstname + lastname + email + remoteAuthToken + unixTime;
byte[] p = Encoding.Default.GetBytes(payload);
byte[] bytes = System.Security.Cryptography.MD5.Create().ComputeHash(p);
string hash = BitConverter.ToString(bytes).Replace("-", "").ToLower();
string url = "https://app.onelogin.com/sessions/remote"
+ "?firstname=" + firstname
+ "&lastname=" + lastname
+ "&email=" + email
+ "×tamp=" + unixTime
+ "&accountid=" + accountId
+ "&hash=" + hash
+ "&launch=" + loginId;
Response.Redirect(url);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>OneLogin embedding demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="repeater1" runat="server">
<ItemTemplate>
<asp:ImageButton OnCommand="App_OnClick" runat="server"
CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "id") %>' ImageUrl='
<%# DataBinder.Eval
(Container.DataItem,
"icon") %>' />
<asp:LinkButton OnCommand="App_OnClick" runat="server"
CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "id") %>'>
<%#DataBinder.Eval(Container.DataItem, "Name")%></asp:LinkButton>
<br />
</ItemTemplate>
</asp:Repeater>
</div>
<div>
<asp:Label ID="lbl" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Have a Question?
Found a problem or a bug? Submit a support ticket.
Looking for walkthroughs or how-to guides on OneLogin's user and admin features? Check out the documentation in our Knowledge Base.
Have a product idea or request? Share it with us in our Ideas Portal.