Get Access token from code RRS feed

  • Question

  • I have an MVC app in which i have two methods inside the Home controller MSLogin and MSAuthorize. In MSLogin the user is redirected to the login page to login using his/her live account, on successful login the user is redirected to the MSAuthorize method and the redirected url contains a code Below are the snippets.


    public ActionResult MSLogin(string userid)
                Session["botuserid"] = userid;
                return Redirect($"{ConfigurationManager.AppSettings["MicrosoftAppId"]}&");

    The redirected URL look something like :, this takes it to MSAuthorize method with the code.

    This the MSAuthorize method :

    public async Task<ActionResult> MSAuthorize(string code)
        { var botCredentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"],
            var stateClient = new StateClient(botCredentials);
            BotState botState = new BotState(stateClient);
            BotData botData = new BotData(eTag: "*");
            botData.SetProperty("AccessToken", access_token);

    I need to save the access token inside the botdata. How do i get the access_token from code. I have gone through few resources online on how to do it but didn't get a clear idea?

    • Moved by CoolDadTx Thursday, December 21, 2017 3:37 PM ASP.NET related
    Thursday, December 21, 2017 4:03 AM

All replies