OAuth 2.0 - Implicit Grant

SmithCart > Integration > REST Endpoints
Usage
Retrieve the JWT access token from Redirection URI
Basic URI
/Services/v1/Authorize.ashx?response_type=token&client_id={clientID}&redirect_uri={redirectURI}&scope={scopes}
Parameters
string clientID           The client ID associated with the callback (redirect URI)
string redirectURI     The callback URI to redirect to with the access token (must be encoded URL)
string scope              The scope(s) that will gives the access to a certain requests (encoded string)
string state               An opaque value used by the client to maintain state between the request
                                and callback. The authorization server includes this value when redirecting
                                the user-agent back to the client
HTTP Example
GET https://domain.com/DesktopModules/Smith.BuyNow/Services/v1/Authorize.ashx?response_type=token&client_id=86iUNrqhsKJhkJQ_&redirect_uri=http%3A%2F%2Flocalhost&scope=private%20orders%20create%20edit%20delete
Service Type
OAuth 2.0 (Login to the portal will be prompt)
 
C# Code
using System.Web;


string clientID = "4SnPA6lqpY76ODEr";
string callbackURL = HttpContext.Current.Request.Url.AbsoluteUri;
string storeURL = "https://mydomain.com/DesktopModules/Smith.BuyNow/Services/v1/";

Response.Redirect(storeURL + "Authorize.ashx?response_type=token&client_id="
    + clientID + "&redirect_uri=" + HttpUtility.UrlEncode(callbackURL)
    + "&scope=" + HttpUtility.UrlEncode("orders create edit delete")
    + "&state=" + randState);
 
 
JavaScript Code
<script>
   (function ($) {
       var CLIENT_ID = "4SnPA6lqpY76ODEr",
           SERVICE_URI = "https://domain.com/DesktopModules/Smith.BuyNow/Services/v1/";

       function getJWT (endPoint, clientID) {
           var jwt = sessionStorage.getItem("jwt");
           if (!jwt) {
               var uri = endPoint + "Authorize.ashx?"
                   + "response_type=token"
                   + "&client_id=" + clientID
                   + "&redirect_uri=" + encodeURIComponent(window.location)
                   + "&scope=" + encodeURIComponent("orders create edit delete")
                   + "&state=" + randState;
               window.location = uri;
               return;
           }
       }

       $(function () {
           var params = {},
               queryString = location.hash.substring(1),
               regex = /([^&=]+)=([^&]*)/g,
               m;

           while (m = regex.exec(queryString)) {
               params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
           }
           if (params["access_token"]) {
               sessionStorage.setItem("jwt", params["access_token"]);
           }

           getJWT (SERVICE_URI, CLIENT_ID);
       });
   })(jQuery);
</script>
 
 
Response
HTTP/1.1 302 Found
Location: https://example.com/#token_type=Bearer&access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..........&expires_in=3600&state=ED0JX6Q46TYB9MK7