Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3271728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:45:23+00:00 2026-05-17T18:45:23+00:00

I can’t find any examples of using DotNetOpenAuth to refresh an expired Access Token

  • 0

I can’t find any examples of using DotNetOpenAuth to refresh an expired Access Token. Most providers don’t use expiring tokens, however Yahoo is a big one that expires their tokens in one hour.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:45:23+00:00Added an answer on May 17, 2026 at 6:45 pm

    Yahoo does use OAuth 1.0, so I figured out how to do it manually:

    First, I try to use the token I have saved in my database. If I get a 401 Unauthorized error, I call my RefreshYahooAccessToken() method, and try again.

    Note: I have my own implementation of a TokenManager that stores my access tokens in a database, as well as any extra data associated with the token (YahooGUID, and oauth_session_handle) which is given to me in Yahoo’s get_token Response Parameters, but you can easily modify it to work with a different TokenManager implementation.

    Here’s my working version:

    try
    {
        request = yahoo.PrepareAuthorizedRequest(YahooContactsAPIEndpoint, TokenManager.currentToken.Token, extraData);
        response = yahoo.Channel.WebRequestHandler.GetResponse(request);
        body = response.GetResponseReader().ReadToEnd();
    }
    catch (DotNetOpenAuth.Messaging.ProtocolException ex)
    {
        //is token expired?
        if (ex.InnerException is WebException
            && ((WebException)ex.InnerException).Response is HttpWebResponse
            && ((HttpWebResponse)((WebException)ex.InnerException).Response).StatusCode == HttpStatusCode.Unauthorized)
        {
            RefreshYahooAccessToken();
            request = yahoo.PrepareAuthorizedRequest(YahooContactsAPIEndpoint, TokenManager.currentToken.Token, extraData);
            response = yahoo.Channel.WebRequestHandler.GetResponse(request);
            body = response.GetResponseReader().ReadToEnd();
        }
    }
    
    
    private static void RefreshYahooAccessToken()
    {
        var request = (HttpWebRequest)WebRequest
            .Create("https://api.login.yahoo.com/oauth/v2/get_token"
                + "?oauth_consumer_key=" + TokenManager.ConsumerKey
                + "&oauth_nonce=" + (new Random()).Next(123400, 9999999).ToString()
                + "&oauth_session_handle=" + TokenManager.GetExtraData("oauth_session_handle") //this value is given to you in the get_token Response Parameters
                + "&oauth_signature=" + TokenManager.ConsumerSecret + "%26" + TokenManager.currentToken.Secret
                + "&oauth_signature_method=PLAINTEXT"
                + "&oauth_timestamp=" + (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds.ToString().Split(new char[] { '.' })[0]
                + "&oauth_token=" + TokenManager.currentToken.Token
                + "&oauth_version=1.0");
        try
        {
            var response = (HttpWebResponse)request.GetResponse();
            var returnStr = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
            var returnData = System.Web.HttpUtility.ParseQueryString(returnStr ?? string.Empty);
            TokenManager.ExpireRequestTokenAndStoreNewAccessToken(null, null, returnData["oauth_token"], returnData["oauth_token_secret"]);
        }
        catch (Exception)
        {
            //User probably revoked token.  Clear the current token, and request authorization again
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone guide me on a possible solution? I don't want to use /bin/cp
Can we close all known/unknown connections to database with the code? I'm using Access
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can I use the Kinect Windows Live Messenger on a PC? I heard rumor
Can someone help me understand why Win32 error codes don't match method signatures and
Can I set a maximum fps? Is there any way to limit fps in
Can we use the asterisk character * for a search action in SQL database?
Can anyone help me trying to find out why this doesn't work. The brushes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.