public CoreServiceResponse AddProvider(string providerName, string clientId, string clientSecret) { try { ApplicationRegistration.Data.Application app = GetServerApplicationOrDie(); OAuthSettingsData data = new OAuthSettingsData() { ApplicationName = app.Name, ApplicationIdentifier = app.Cuid, ProviderName = providerName, ClientId = clientId, ClientSecret = clientSecret }; OAuthClientSettings settings = OAuthSettingsRepository.Save(data).CopyAs <OAuthClientSettings>(); return(new CoreServiceResponse { Success = true, Data = settings }); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }
public AuthorizationService( OAuthClientSettings oAuthClientSettings, OAuthToken token, HttpClient httpClient ) : base(httpClient) { _oAuthClientSettings = oAuthClientSettings; _token = token; }
protected async Task <HttpRequestMessage> GetAuthenticatedHttpRequestMessage( HttpMethod httpMethod, string endPoint, OAuthClientSettings credentials, List <KeyValuePair <string, string> > post = null) { var result = await GetHttpRequestMessage(httpMethod, endPoint, post); result.Headers.Authorization = new AuthenticationHeaderValue( "Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{credentials.Id}:{credentials.Secret}")) ); return(result); }
public async Task <TResult> GetApiResult <TResult>( HttpMethod httpMethod, string endPoint, OAuthClientSettings credentials = null, List <KeyValuePair <string, string> > post = null) { var request = credentials == default ? await GetHttpRequestMessage(httpMethod, endPoint, post) : await GetAuthenticatedHttpRequestMessage(httpMethod, endPoint, credentials, post); var apiResult = await HttpClient.SendAsync(request); ProcessHttpHeaders(apiResult); return(await GetProcessedResult <TResult>(apiResult)); }
public OAuthEntityApp(string serviceUrl) : base() { var data = AddArea("data"); // Note: we have to specify redirect URL explicitly here; for real world apps the redirect URL may be left null - // it will be configured automatically by OAuthClientModule on first web api call // (see EntityApp.WebInitialize, OAuthClientModule.WebInitialize). But in this demo app the initialization will // happen only when the controller is hit (by redirect) - but we need to know redirect URL before that. // This is URL of RedirectController - it will handle redirects from remote OAuth server var oauthStt = new OAuthClientSettings(redirectUrl: serviceUrl + "/api/oauth_redirect", defaultAccountName: "TestAccount", redirectResponseText: "Authorization completed, please return to OAuthDemoApp."); //Note for redirectResponseText: alternatively you can specify after-redirect landing page (another redirect from RedirectController) var oauth = new OAuthClientModule(data, oauthStt); var dbInfo = new Modules.DbInfo.DbInfoModule(data); var encrData = new Modules.EncryptedData.EncryptedDataModule(data); this.ApiConfiguration.RegisterController(typeof(Vita.Modules.OAuthClient.Api.OAuthRedirectController)); }
public AuthenticationService(OAuthClientSettings oAuthClientSettings, HttpClient httpClient) : base(httpClient) { _oAuthClientSettings = oAuthClientSettings; }