Skip to content

Commit

Permalink
ready to call ANet API from app
Browse files Browse the repository at this point in the history
  • Loading branch information
sqamara committed Aug 18, 2017
1 parent 11b2a65 commit 0b327ea
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 34 deletions.
49 changes: 40 additions & 9 deletions OAuthDemo/Controllers/DemoController.cs
Expand Up @@ -28,17 +28,48 @@ public ActionResult RedirectMerchant(OAuthDemo.Models.Demo client)

public ActionResult RetrieveAccessToken(OAuthDemo.Models.Demo client)
{
RetrievingRefreshingApi instance = new RetrievingRefreshingApi();
string grantType = "authorization_code";
string clientId = "4dp5b7gRqk";
string code = "novp2e";
string clientSecret = "fa3a5b16753d09b24bb44243605a4a98";
string refreshToken = null;
int? platform = 2;
var response = instance.GetToken(grantType, clientId, code, clientSecret, refreshToken, platform);
System.Diagnostics.Debug.WriteLine(response);
System.Diagnostics.Debug.WriteLine(client);

try
{
RetrievingRefreshingApi instance = new RetrievingRefreshingApi();
var response = instance.GetToken(grantType: client.GrantType, clientId: client.Id, code: client.Code, clientSecret: client.Secret, platform: client.platform);
//System.Diagnostics.Debug.WriteLine(response.ToJson());
client.Step3Response = response.ToJson();
client.RefreshToken = response.RefreshToken;
}
catch
{
client.Step3Response = OAuthDemo.Models.Demo.RetrieveErrorResponse;
}

return View("Index", client);
}

public ActionResult RefreshAccessToken(OAuthDemo.Models.Demo client)
{
ModelState.Clear();

System.Diagnostics.Debug.WriteLine(client);

try
{
RetrievingRefreshingApi instance = new RetrievingRefreshingApi();
var response = instance.GetToken(grantType: client.GrantType, clientId: client.Id, refreshToken: client.RefreshToken);
//System.Diagnostics.Debug.WriteLine(response.ToJson());
client.Step5Response = response.ToJson();
}
catch
{
client.Step5Response = OAuthDemo.Models.Demo.RefreshErrorResponse;
}

return View("Index", client);
}

public ActionResult RedirectRevokePermissions()
{
return Redirect(OAuthDemo.Models.Demo.RevokePermissionsUrl);
}
}
}
11 changes: 9 additions & 2 deletions OAuthDemo/Models/DemoModels.cs
Expand Up @@ -8,6 +8,11 @@ namespace OAuthDemo.Models
{
public class Demo
{
public static string RetrieveErrorResponse = "Error Retrieving the Access Token";
public static string RefreshErrorResponse = "Error Refreshing the Access Token";
public static string RevokePermissionsUrl = "https://sandbox.authorize.net/UI/themes/sandbox/Settings/ResellerDelegation.aspx";


public Demo()
{
Id = "4dp5b7gRqk";
Expand All @@ -18,6 +23,7 @@ public Demo()
Sub = "oauth";
updateRedirectMerchantUrl();
GrantType = "authorization_code";
platform = 2;
}

// Step 1
Expand All @@ -43,12 +49,13 @@ public void updateRedirectMerchantUrl()
// Step 3
public string GrantType { get; set; }
public string Code { get; set; }

public string Step3Response { get; set; }
public int? platform { get; set; }
// Step 4

// Step 5
public string RefreshToken { get; set; }

public string Step5Response { get; set; }

override public string ToString()
{
Expand Down
48 changes: 25 additions & 23 deletions OAuthDemo/Views/Demo/Index.cshtml
Expand Up @@ -35,23 +35,23 @@
<div class="form-group">
@Html.LabelFor(m => m.Id, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly", Value = Model.Id })
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly"})
</div>
@Html.LabelFor(m => m.RedirectUri, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.RedirectUri, new { @class = "form-control", @readonly = "readonly", Value = Model.RedirectUri })
@Html.TextBoxFor(m => m.RedirectUri, new { @class = "form-control", @readonly = "readonly"})
</div>
@Html.LabelFor(m => m.Scope, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Scope, new { @class = "form-control", Value = Model.Scope })
@Html.TextBoxFor(m => m.Scope, new { @class = "form-control"})
</div>
@Html.LabelFor(m => m.State, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.State, new { @class = "form-control", Value = Model.State})
@Html.TextBoxFor(m => m.State, new { @class = "form-control"})
</div>
@Html.LabelFor(m => m.Sub, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Sub, new { @class = "form-control", @readonly = "readonly", Value = Model.Sub })
@Html.TextBoxFor(m => m.Sub, new { @class = "form-control", @readonly = "readonly" })
</div>
@Html.LabelFor(m => m.RedirectMerchantUrl, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
Expand All @@ -60,68 +60,60 @@
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Go to RedirectMerchantUrl" />
<input type="submit" class="btn btn-default" value="Redirect Merchant" />
</div>
</div>
}

@*<div class="col-md-10">
@Html.LabelFor(m => m.Code, new { @class = "col-md-2 control-label" })
@Html.TextBoxFor(m => m.Code, new { @class = "form-control" })
@Html.LabelFor(m => m.State, new { @class = "col-md-2 control-label" })
@Html.TextBoxFor(m => m.State, new { @class = "form-control" })
</div>*@

<h4>Step 3. Retrieving the Access Token</h4>
@using (Html.BeginForm("RetrieveAccessToken", "Demo", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="form-group">
@Html.LabelFor(m => m.GrantType, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.GrantType, new { @class = "form-control" })
@Html.TextBoxFor(m => m.GrantType, new { @class = "form-control", @readonly = "readonly"})
</div>
@Html.LabelFor(m => m.Code, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Code, new { @class = "form-control" })
</div>
@Html.LabelFor(m => m.Id, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly", Value = Model.Id })
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly"})
</div>
@Html.LabelFor(m => m.Secret, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Secret, new { @class = "form-control", @readonly = "readonly", Value = Model.Secret })
@Html.TextBoxFor(m => m.Secret, new { @class = "form-control", @readonly = "readonly"})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Next" />
<input type="submit" class="btn btn-default" value="Submit Token Request" />
</div>
</div>
}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<p>Response:</p>
@Html.TextArea("Step3Response", null, new { cols = "55", rows = "10" })
@Html.TextArea("Step3Response", null, new { rows = 10, cols = 50, value = Model.Step3Response })
</div>
</div>


<h4>Step 4. Submitting API Requests</h4>
<p>???????????</p>
<p>//TODO: could use existing ANET api, or use existing swagger merged with token swagger or, cherrypick from existing swagger merged with token swagger </p>

<h4>Step 5. Refreshing the Access Token</h4>
@using (Html.BeginForm("RefreshAccessToken", "Demo", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="form-group">
@Html.LabelFor(m => m.Id, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly", Value = Model.Id })
@Html.TextBoxFor(m => m.Id, new { @class = "form-control", @readonly = "readonly"})
</div>
@Html.LabelFor(m => m.GrantType, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.GrantType, new { @class = "form-control" })
@Html.TextBoxFor(m => m.GrantType, new { @class = "form-control", @readonly = "readonly", Value = "refresh_token" })
</div>
@Html.LabelFor(m => m.RefreshToken, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
Expand All @@ -131,7 +123,7 @@

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Next" />
<input type="submit" class="btn btn-default" value="Submit Token Refresh" />
</div>
</div>
}
Expand All @@ -142,3 +134,13 @@
@Html.TextArea("Step5Response", null, new { cols = "55", rows = "10" })
</div>
</div>

<h4>Revoking Permissions</h4>
@using (Html.BeginForm("RedirectRevokePermissions", "Demo", FormMethod.Post, new { @class = "form-horizontal", role = "form", target = "_blank" }))
{
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Redirect to Revoke" />
</div>
</div>
}

0 comments on commit 0b327ea

Please sign in to comment.