none
Extract access token from the URL RRS feed

  • Question

  • I need to extract the access_token from the below URL. Home is the ControllerName and MSAuthorize is the action name to which after a User logs in into login.live.com is redirected to. Now I am inside the MSAuthorize method and i need to access the access token value in the URL, How to do it?:

    https://hitachiintegratedcrmbot.azurewebsites.net/Home/MSAuthorize#access_token=xxxxx&token_type=bearer&expires_in=3600&scope=wl.basic%

    20wl.offline_access%20wl.signin%20wl.birthday%20wl.calendars%20wl.calendars_update%20wl.contacts_birthday

    %20wl.contacts_create%20wl.contacts_calendars%20wl.contacts_photos%20wl.contacts_skydrive%20wl.emails%

    20wl.events_create%20wl.imap%20wl.phone_numbers%20wl.photos%20wl.postal_addresses%20wl.skydrive%20wl.sk

    ydrive_update%20wl.work_profile%20office.onenote_create&user_id=AAAAAAAAAAAAAAAAAAAAAOSoGrlq8pnnJxF8G4OAt00

    Note : There is a # before access_token in the URL due to which i am not able to access it in the query parameters
    • Edited by Tanmoy Paul 08 Wednesday, December 20, 2017 1:07 PM
    • Moved by Fei Hu Thursday, December 21, 2017 5:33 AM ASP.NET related
    Wednesday, December 20, 2017 1:06 PM

All replies

  • The simplest approach, in my opinion, is to simply do a string search on the url fro #access_token=. Then grab everything after that until &.

    Another approach, if you know this is the only #, is to use Replace to switch the # to a ? and then use Uri to parse it out.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 20, 2017 2:38 PM
  • But how do i access the URL when i am inside the redirected method i.e the URL...I tried System.Web.HttpContext.Current.Request.Url.ToString(); but it dosen't read anything after #.
    Wednesday, December 20, 2017 2:57 PM
  • Questions related to MVC should be posted in the ASP.NET forums.

    The Request object has the raw URL.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 20, 2017 3:03 PM