This document is used to assist developers with the way how to integrate authorization code grant type of C# SDK with your client applications.
Platform = new SDKModel().GenerateSDK().GetPlatform();
AuthCodeParams = new Dictionary<string, string>
{
{"response_type", "code" },
{"client_id", "8GtalMrJRA2JnozdtdWTlg" },
{"redirect_uri", "https://localhost:3000/redirect" },
{"prompt", "login consent" },
{"state", "statebyStephenHe" },
};
SessionHelper.Set("state", AuthCodeParams["state"]);
SessionHelper.Set("redirect_uri", AuthCodeParams["redirect_uri"]);
public ActionResult Index()
{
return Redirect(Platform.AuthUrl(AuthCodeParams));
}
Enter the provided phone number and password, and click login button
- Username (phone number): 16505496100
- Password: rcEngineering@1!
If the authorize button above is hit, the code and state will be delivered after redirecting page.
string code = Request.QueryString["code"];
string state = Request.QueryString["state"];
With the 2 parameters and redirectUri provided before, you are able to retrieve access tokens and others by using following code.
var response = Platform.AuthorizeByAuthCode("authorization_code", code, initialRedirectUri);
The response contains following parameters that is required to map with corresponding dictionary keys.
JToken token = JObject.Parse(response.GetBody());
tokenResponseModel = new TokenResponseModel()
{
AccessToken = (string)token.SelectToken("access_token"),
ExpireIn = (string)token.SelectToken("expires_in"),
RefreshToken = (string)token.SelectToken("refresh_token"),
RefreshToken_ExpireIn = (string)token.SelectToken("refresh_token_expires_in"),
Scope = (string)token.SelectToken("scope"),
TokenType = (string)token.SelectToken("token_type"),
OwnerId = (string)token.SelectToken("owner_id"),
EndpointId = (string)token.SelectToken("endpoint_id")
};