public static void DoSomeOauth2()
        {
            var request_factory = new OAuth2.Infrastructure.RequestFactory();

            request_factory.CreateRequest();
            request_factory.CreateClient();



            var config = new OAuth2.Configuration.RuntimeClientConfiguration();

            config.ClientId     = CLIENT_ID;
            config.ClientSecret = CLIENT_SECRET;
            config.RedirectUri  = REDIRECT.ToString();



            var oauthin = new OAuth2.Client.Impl.GoogleClient(request_factory, config);

            oauthin.GetCurrentToken();



            service        = new RequestService(HANDLER);
            Program.config = new CanvasConfig(DOMAIN, CLIENT_ID, CLIENT_SECRET, REDIRECT);

            var request = new ApiRequest(new Uri("https://instantadmin.instructure.com/login/oauth2/auth"))
                          .Param("client_id", CLIENT_ID)
                          .Param("response_type", "code")
                          .Param("redirect_uri", REDIRECT.ToString())
            ;

            //var basic = await HANDLER.ExecuteAsync<OAuth2Session>(request).ConfigureAwait(false);

            //session = new OAuth2Session(access_token, refresh_token, expires_in, token_type);
            auth = new AuthRepository(Program.config, service, CONVERTER);

            client = new Client(Program.config, auth);

            //var courses = await client.CoursesManager.GetAll();

            //foreach(var course in courses)
            //{
            //    Console.WriteLine(course.ToString());
            //}


            //return;
        }
        public Google()
        {
            var secrets = SecretsClient.Get("google");

            var config = new RuntimeClientConfiguration()
            {
                ClientId = secrets.Key,
                ClientSecret = secrets.Secret,
                Scope = @"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
                RedirectUri = "urn:ietf:wg:oauth:2.0:oob"
            };

            client = new GoogleClient(new RequestFactory(), config);

            AccessToken = Configuration.GoogleRefreshToken;
        }
        public IHttpActionResult Google(JObject value) {
            var authInfo = value.ToObject<ExternalAuthInfo>();
            if (authInfo == null || String.IsNullOrEmpty(authInfo.Code))
                return NotFound();

            if (String.IsNullOrEmpty(Settings.Current.GoogleAppId) || String.IsNullOrEmpty(Settings.Current.GoogleAppSecret))
                return NotFound();

            var client = new GoogleClient(new RequestFactory(), new RuntimeClientConfiguration {
                ClientId = Settings.Current.GoogleAppId,
                ClientSecret = Settings.Current.GoogleAppSecret,
                RedirectUri = authInfo.RedirectUri
            });

            UserInfo userInfo;
            try {
                userInfo = client.GetUserInfo(authInfo.Code);
            } catch (Exception ex) {
                return BadRequest("Unable to get user info.");
            }

            User user;
            try {
                user = AddExternalLogin(userInfo);
            } catch (Exception ex) {
                return BadRequest("An error occurred while processing user info.");
            }

            if (user == null)
                return BadRequest("Unable to process user info.");

            if (!String.IsNullOrEmpty(authInfo.InviteToken))
                AddInvitedUserToOrganization(authInfo.InviteToken, user);

            return Ok(new { Token = GetToken(user) });
        }