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.live.com 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($"https://login.live.com/oauth20_authorize.srf?client_id={ConfigurationManager.AppSettings["MicrosoftAppId"]}&redirect_uri=https%3A%2F%2Fhitachiintegratedcrmbot.azurewebsites.net%2FHome%2FMSAuthorize&response_type=code&scope=wl.basic+wl.offline_access+wl.signin+wl.birthday+wl.calendars+wl.calendars_update+wl.contacts_birthday+wl.contacts_create+wl.contacts_calendars+wl.contacts_photos+wl.contacts_skydrive+wl.emails+wl.events_create+wl.imap+wl.phone_numbers+wl.photos+wl.postal_addresses+wl.skydrive+wl.skydrive_update+wl.work_profile+office.onenote_create");

    The redirected URL look something like :https://hitachiintegratedcrmbot.azurewebsites.net/Home/MSAuthorize?code=M22264859-82d5-5f03-775a-c92bf93b2e7e, 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

  • Please post questions related to MVC in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, December 21, 2017 3:37 PM