All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.oauth.impl.GitHubHander Maven / Gradle / Ivy

There is a newer version: 1.8.31
Show newest version
package com.quhaodian.user.oauth.impl;

import com.google.gson.Gson;
import com.quhaodian.user.oauth.api.OauthHandler;
import com.quhaodian.user.oauth.domain.GitHubUser;
import com.quhaodian.user.oauth.domain.OauthResponse;
import com.quhaodian.user.oauth.domain.TokenResponse;
import com.quhaodian.utils.http.Connection;
import com.quhaodian.utils.http.HttpConnection;

public class GitHubHander implements OauthHandler {
  @Override
  public void setKey(String key) {

  }

  @Override
  public void setSecret(String secret) {

  }

  @Override
  public OauthResponse login(String access_token, String openid) {
    GitHubUser result = null;

    Gson gson = new Gson();

    Connection info = HttpConnection.connect("https://api.github.com/user");

    info.data("access_token", access_token);
    info.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");
    String infojson;
    try {
      infojson = info.execute().body();
      result = gson.fromJson(infojson, GitHubUser.class);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return result;
  }

  @Override
  public TokenResponse getToken(String code) {
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy