User Tools

Site Tools


web-integration:c-sharp-example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
web-integration:c-sharp-example [2019/08/05 11:22]
tjotov
web-integration:c-sharp-example [2019/08/05 11:27] (current)
tjotov
Line 2: Line 2:
 C# relies on Web services for ADUCID - or WSA, see [[web-integration:basics|Server side integration basics]] C# relies on Web services for ADUCID - or WSA, see [[web-integration:basics|Server side integration basics]]
  
-=== Import WSDL into your project in Visual Studio. ===+Import WSDL into your project in Visual Studio.
  
 Create an instance of **AducidApiJsonServiceClient**. Create an instance of **AducidApiJsonServiceClient**.
Line 56: Line 56:
 Just simple "Rewrite" from WSA to C# with authId check Just simple "Rewrite" from WSA to C# with authId check
 <sxh csharp> <sxh csharp>
-//We have to "proxy" AIM reponses to Web APIuising this page+            //We have to "proxy" AIM reponses to Web APIuising this page
             var aducid = new AducidApiServiceClient();             var aducid = new AducidApiServiceClient();
             context.Response.ContentType = "application/json";             context.Response.ContentType = "application/json";
Line 89: Line 89:
  
 <sxh csharp> <sxh csharp>
-var aducid = new AducidApiJsonServiceClient(); +            var aducid = new AducidApiServiceClient(); 
-//read authId from you session +            string query = context.Request.QueryString.ToString(); 
-string authId = (string)context.Session["123"]+            var queryParsed = HttpUtility.ParseQueryString(query); 
-var aducidResult = aducid.getResult(authId, null); +            var id = queryParsed["id"]; 
-//parse json +            //get authId from session 
-dynamic aducidResultObj = JsonConvert.DeserializeObject(aducidResult); +            string authId = (string)context.Session[id]; 
-//User primary key i.e. UDI +            context.Response.ContentType = "application/json"; 
-var udi = aducidResultObj.data.userDatabaseIndex; +            try 
-//key to further ADUCID operetions on user object (with authId) +            { 
-string authKey2 = aducidResultObj.data.authKey2+                //call AIM to get operation result 
-//prepare response +                var aducidResult = aducid.getResult(authId, null); 
-var response = aducid.endAuthenticationSession(authId, authKey2); +                //User Database Index, i.e. UDI 
-context.Response.ContentType = "text/plain"; +                var udi = aducidResult.userDatabaseIndex; 
-//OK do something with your session +                //authKey (with authId) used to access user data later from AIM 
-//... +                var authKey2 = aducidResult.authKey
-//send response +                //finalize authentication and get respoonse form Web API 
-context.Response.Write(response);+                var response = aducid.endAuthenticationSession(authId, authKey2); 
 +                //AUTHENTICATED 
 +                FormsAuthentication.SetAuthCookie("auth", false); 
 +                //send Web API the result - by default it will redirect to URI we provided earlier; for iOS PEIG opens this URI directly 
 +                context.Response.Write(aducid.toJson(response, "authenticated"))
 +            } 
 +            catch (System.ServiceModel.FaultException e) 
 +            { 
 +                //handle error 
 +                var msgFault = e.CreateMessageFault(); 
 +                var errorResult = msgFault.GetDetail<AducidClientException>().result; 
 +                //get error as JSON 
 +                var response = aducid.toErrorJson(errorResult, "error"); 
 +                //send JSON to Web API 
 +                context.Response.Write(response); 
 +            }
 </sxh> </sxh>
  
  
 === Prepare a web page === === Prepare a web page ===
-This page should contain [[integration-api:start|ADUCID Integration API]]\\+This page should contain [[web-integration:client-side|Client API for Web Integration]]\\
 Provide start, check and proxy Url. Provide start, check and proxy Url.
-<sxh>  
-   aducid.setStartOperationUrl("open"); 
-   aducid.setResultOperationUrl("openCheck"); 
-   aducid.setProxyUrl("proxy"); 
-</sxh> 
 Override what should be done after authentication / operation: Override what should be done after authentication / operation:
-<sxh>  +<sxh javascript
-   aducid.processResult = function (result) {+     <script type="text/javascript"> 
 +        var aducid = new ADUCID(); 
 + 
 +        $(document).ready(function () { 
 +            aducid.setAuthentication(); 
 +            //operation start URL 
 +            aducid.setStartOperationUrl("open"); 
 +            //operation check URL 
 +            aducid.setResultOperationUrl("openCheck"); 
 +            //proxy helper URL 
 +            aducid.setProxyUrl("proxy"); 
 + 
 +            //text under QR code 
 +            aducid.showQRHint = function (param) { 
 +                $('#qr-code-hint').html("Use your PEIG to authenticate"); 
 +            } 
 + 
 +            //running operation texr 
 +            aducid.showRunningHint = function (param) { 
 +                $('#qr-code-hint').html("Please wait ..."); 
 +            } 
 + 
 +            //called when auth finished (except iOS) 
 +            aducid.processResult = function (result) { 
 +                alert("Auth finished. Result: " + JSON.stringify(result));
                 if (result.status == "OK") {                 if (result.status == "OK") {
-                    alert("atuhenticated"); +                    location.href = result.redirect;
-                    //location.reload();+
                 }                 }
                 else {                 else {
-                    alert("atuhentication failure");+                    location.href = result.redirect;
                 }                 }
             }             }
 +
 +            //handle PEIG not installed error
 +            aducid.showPeigError = function () {
 +                showDialog("Problem with PEIG", "PEIG is not installed", "error", function () {
 +                    location.reload();
 +                });
 +            }
 +
 +            //handle communication or other error
 +            aducid.handleError = function (result) {
 +                showDialog("General error", result.data.message, "error", function () {
 +                    location.href = result.redirect;
 +                });
 +            }
 +
 +            //GUI mapping
 +            //button associated to start auth
 +            aducid.setButton($("#main-button"));
 +            //locatino of QR code img
 +            aducid.setQrCode($("#qr-code"));
 +            //location of text under QR code
 +            aducid.setQrHint($("#qr-code-hint"));
 +
 +            //start; false as we wait for button click or qr scan
 +            aducid.init(false);
 +        });
 +    </script>
 </sxh>  </sxh> 
  
Line 133: Line 193:
  
 <sxh html> <sxh html>
-<h1>ADUCID Hello World example</h1>+    <div class="container"> 
 +        <h1>ADUCID Hello World example</h1>
         <div class="row">         <div class="row">
             <div class="col-xs-8 col-xs-offset-2">             <div class="col-xs-8 col-xs-offset-2">
Line 159: Line 220:
             </div>             </div>
         </div>         </div>
 +    </div>
 </sxh> </sxh>
web-integration/c-sharp-example.1565004150.txt.gz · Last modified: 2019/08/05 11:22 by tjotov