Skip to content

Instantly share code, notes, and snippets.

@jekku
Last active October 27, 2015 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jekku/7213e27588308e75dd28 to your computer and use it in GitHub Desktop.
Save jekku/7213e27588308e75dd28 to your computer and use it in GitHub Desktop.
Authenticating Third Party Apps to accounts.freedom.tm

##Prerequisites

    1. accounts.freedom.tm must recognize your service, and should be listed in its database.
    1. Aside from service recognition, you must have valid redirect URIs in your app.

##Authentication procedure flow from third party app(In javascript)

    1. Redirect to api.accounts.freedom.tm/auth with the following Parameters.
    • a.) service - the service name.
    • b.) redirect_uri - URL to redirect back to your app on login
    • c.) response_type - The type of response needed (e.g. code)
    • d.) roles - Roles requested (email, admin, profile)

In code, you may have something like :

    <a href="http://api.accounts.freedom.tm/auth?service=earnings&redirect_uri=http://dev.earnings.tm:3000/profiler&reponse_type=code&roles=profile,email,partner"> Log In With Freedom </a>

Or even :

res.redirect('http://api.accounts.freedom.tm/auth?service=earnings&redirect_uri=http://dev.earnings.tm:3000/profiler&reponse_type=code&roles=profile,email,partner');
    1. The next important step is to prepare the redirect URI. It should be able to handle a get request, and it will have the access token alongside it.

Controller

import * as cudl from 'cuddle'; //import a cURL library
//receives get request as according to defined routes.    
export freedom_callback = (req, res, next) => {
    let access_token = req.query.access_token; //REMEMBER TO GET THE ACCESS TOKEN.
};
    1. Basically do whatever is needed to be done with the access token.

For example, you can use this access token to actually grab the user profile of its owner.

    curl -H '"Access-Token" : "a6we3-mj7Il-GYTas-3RtxA"' api.accounts.freedom.tm/user

The above will return :

    {
        first_name : 'Annie',
        last_name : 'Batumbakal',
        email : 'dispachadora@gmail.com',
        //along with other details associated with the account.
    }

The same can be done in any other programming language, and this data can prove valuable to sessions, profile dashobards, etc.

Possible Errors for third party app connections

1. Redirect URI Mismatch

This happens when you supplied the wrong redirect_uri parameter to /auth. Make sure your URL is listed
by the server admin.

2. Service Not Found

Might be the cause of a typo or an inexistent service supplied to service parameter on /auth.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment