using System.Linq; using System.Collections.Generic; using Nancy; using Nancy.ModelBinding; using Sony.Filtr.Applications; using Sony.Filtr.Contracts.Abstractions; using Sony.Filtr.Contracts.Entities; using Sony.Filtr.Contracts.Definitions; using System; using System.Net.Http; using Amazon.CloudSearch.Model; using AutoMapper; using Sony.Filtr.SoundCloud.Model; namespace Sony.Filtr.AdminAPI.Modules { public class ServiceAccountAuthModule : NancyModule { public ServiceAccountAuthModule(ApplicationInstanceManager applicationInstanceManager, IServiceAccountManager serviceAccountManager) { //Get["SoundcloudCallback", "/serviceAccounts/soundcloudcallback/", true] = async (parameters, cancellationToken) => //{ // var accessCode = (string)Request.Query.code; // var url = $"https://api.soundcloud.com/oauth2/token"; // var client = new HttpClient(); // var formDictionary = new Dictionary() // { // { "client_id", "22d200cb2449f4028bcf9d6381fb2a6f" }, // { "client_secret", "67a49c0de2d126788bbf36e5954cd414" }, // { "grant_type", "authorization_code" }, // {"redirect_uri", "http://adminapi.filtr.local.circuit.se/serviceAccounts/soundcloudcallback" }, // {"code", accessCode } // }; // var response = await client.PostAsync(url, new FormUrlEncodedContent(formDictionary)); // var soundCloudResponse = await response.Content.ReadAsAsync(); // if (string.IsNullOrWhiteSpace(soundCloudResponse.access_token)) // { // throw new Exception("Usch. Ingen access-token."); // } // var account = new ServiceAccount(); // account.AccessToken = soundCloudResponse.access_token; // account.ApplicationId = 6; // account.DisplayName = "SoundCloud-konto"; // TODO // account.ServiceType = ServiceType.SoundCloud; // account.RefreshToken = soundCloudResponse.refresh_token; // account.AccessTokenExpiry = soundCloudResponse.expires_in; // serviceAccountManager.AddServiceAccount(account); // return HttpStatusCode.OK; //}; } } }