Top 1% !
Popularity: 13179th place

Published on:


MailUp REST API - How to authenticate with 3 leg process flow

This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 3 leg authentication.
You can start digging into the MailUP API world by reading this content:
An instance of MailUpClient class is able to manage one user at a time. 
A MailUpClient object needs a pair clientID-clientSecret, which you can retrieve following this procedure:
Then, the user logins with his/her credentials to be entered in the MailUp form; from the serve side, a code is sent to the server which can be used to invoke RetrieveAccessToken(code) method (it should be done just only once at the beginning of the process)
Finally, you can call all the methods you want!
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
@using MailUp.Sdk.Base @using MailUp.Framework.Contracts.API.Base @using MailUp.Framework.Contracts.API.DataContracts.Console @{ Layout = "~/_SiteLayout.cshtml"; Page.Title = "Welcome to the sample client to interact with MailUp REST API"; MailUpClient mailUp = Session["MailUpClient"] as MailUpClient; string receivedCode = Request["code"]; string redirUri = string.Empty; string accessTokenRetrieval = "Your application has been granted. You are now able to consume MailUp API!"; if (string.IsNullOrEmpty(receivedCode)) { // Phase 1: the authorization flow should be started with the redirection towards MailUp login form redirUri = mailUp.GetLogOnUri(Request.Url.AbsoluteUri); } else { // Phase 2: the MailUp login form redirected the user back to this page, with the code to be exchanged // with access token to securely consume REST API: try { mailUp.RetrieveAccessToken(receivedCode); //invoke a sample API: CollectionOf<ConsoleListItem> lists = mailUp.GetLists("", "idList ASC", 1); if ((lists != null) && (lists.Count > 0)) { accessTokenRetrieval += " E.g. your first list is named '" + lists[0].Name + "'"; } } catch (MailUpException ex) { accessTokenRetrieval = "Unable to access the service due to " + ex.Message; } } } <p> Click here to start the authorization process. <br /> The MailUp login page will be displayed and you will be able to enter your username and password. <br /> Then, you will be redirected back here, with a valid access token that can be used to perform all the REST calls. <br /> <br /> @if (string.IsNullOrEmpty(receivedCode)) { <input id="authFlowBtn" type="button" value="Login" onclick="javascript:document.location='@redirUri';" /> } else { <text>@accessTokenRetrieval</text> } </p>
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus