{"size": 1661, "ext": "js", "max_stars_repo_path": "src/auth.js", "max_stars_repo_name": "fablabbcn/fablabsjs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/auth.js", "max_issues_repo_name": "fablabbcn/fablabsjs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/auth.js", "max_forks_repo_name": "fablabbcn/fablabsjs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.7903225806, "max_line_length": 65, "alphanum_fraction": 0.5400361228}
import querystring from 'querystring'
import axios from 'axios'


export default class Auth {

    constructor(config){
        this.config = config
    }


    authorize_url(){
        const config = this.config
        const location =  
            config.base_url + 
            config.authorize_url + '?' + 
            querystring.stringify({
                'client_id' : config.client_id,
                'redirect_uri': config.redirect_url,
                'response_type': 'code'
                })
        return location
    }

    async revoke_token(token){
        const config = this.config
        const result = await axios.delete( 
            config.base_url + config.token_url, 
            querystring.stringify({
            client_id: config.client_id,
            client_secret: config.client_secret,
            access_token: access_token,
            redirect_uri: config.redirect_url
          }),{
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
        return result
    }


    async request_token(code){
        const config = this.config
        const result = await axios.post( 
            config.base_url + config.token_url, 
            querystring.stringify({
            client_id: config.client_id,
            client_secret: config.client_secret,
            code: code,
            grant_type: 'authorization_code',
            redirect_uri: config.redirect_url
          }),{
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
        const token = result.data
        return token
    }

}