Coder Social home page Coder Social logo

freeagent's Introduction

.NET client for FreeAgent (freeagent.com) API (v2)

This is very much a work in progress. Eventually, you should be able to do this, which is stolen (like a lot of this) from DropNet

How do I use it?

The Client:

To use FreeAgentClient you need an instance of the FreeAgentClient class, this class does everything for FreeAgentClient. This class takes the API Key and API Secret (These must be obtained from FreeAgent to access the API).

    //OPTIONAL
    FreeAgentClient.UseSandbox = true;
    
    _client = new FreeAgentClient("API KEY", "API SECRET");
Login/Tokens:

FreeAgent requires a web authentication to get a usable token/secret, so this is a 3 step process.

Step 1. Authorize App with FreeAgent - This step involves sending the user to a login page on the FreeAgent site and having them authenticate there. The FreeAgent client has a function to return the url for you but the rest must be handled in app, this function also takes a callback url for redirecting the user to after they have logged in. (NOTE: The token still cant be used yet.)

    string callbackUri = "http://your-server.com/something";
    string url = client.BuildAuthorizeUrl(callbackUri);
    
    //Send the user to the url in a browser so the user can login

Open a browser with the url returned by BuildAuthorizeUrl - After we have the authorize url we need to direct the user there (use some sort of browser here depending on the platform) and navigate the user to the url. This will prompt them to login and authorize your app with the API.

Step 2. Get an Access Token from the URL code and Request Token - This is the last stage of the process, converting the oauth request token into a usable FreeAgent API token. This function will use the clients stored Request Token but this can be overloaded if you need to specify a token to use.

    string code = client.ExtractCodeFromUrl(url);
			
	var newToken = client.GetAccessToken (code, callbackUri);
	
    
    //Store this newToken.accessToken so we dont have to do all of this next time!

Once you have a token:

			FreeAgentClient.UseSandbox = true;

            var Client = new FreeAgentClient(KeyStorage.AppKey, KeyStorage.AppSecret);

            var token = new AccessToken
            {
                access_token = "",
                refresh_token = KeyStorage.RefreshToken,
                token_type = "bearer"
            };

            Client.CurrentAccessToken = token;


            var Token = Client.RefreshAccessToken();

            if (Token == null || string.IsNullOrEmpty(Token.access_token) || string.IsNullOrEmpty(Token.refresh_token))
            {
                throw new Exception("Could not setup the Token");
            }

freeagent's People

Contributors

djcparker avatar mattwoberts avatar nicwise avatar

Watchers

 avatar  avatar

Forkers

endjin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.