/// <summary> /// This method is responsible for returning Oauth tokens from the specified code. /// </summary> /// <param name="code">The code which is used to retrieve Oauth tokens from the external data source.</param> /// <returns>This method returns the Oauth tokens from the external data source.</returns> public async Task <OauthTokens> GetTokens(string code) { IAuthorizedDataSourceAdaptee dataProvider = adaptee as IAuthorizedDataSourceAdaptee; if (dataProvider == null) { throw new NotSupportedException("Can not cast specified adaptee to authorized adaptee."); } return(await dataProvider.GetTokens(code)); }
private async Task <IEnumerable <Project> > GetAllProjectWithAccessToken(string accessToken) { IAuthorizedDataSourceAdaptee authorizedDataSourceAdaptee = adaptee as IAuthorizedDataSourceAdaptee; if (authorizedDataSourceAdaptee == null) { throw new NotSupportedException("Can not cast specified adaptee to authorized adaptee."); } IEnumerable <Project> projects = await authorizedDataSourceAdaptee.GetAllProjects(accessToken); return(projects); }
/// <summary> /// This method is responsible for retrieving a project by guid. /// </summary> /// <param name="token">The token parameters is used for finding all projects. This can be Oauth tokens, or the username.</param> /// <param name="id">The identifier which is used for searching an individual project.</param> /// <param name="needsAuth">The needsAuth parameter specifies which flow should get used.</param> /// <returns>This method returns a project with the specified identifier.</returns> public async Task <Project> GetProjectByGuid(string token, string id, bool needsAuth) { if (!needsAuth) { IPublicDataSourceAdaptee publicDataSource = adaptee as IPublicDataSourceAdaptee; if (publicDataSource == null) { throw new NotSupportedException("Can not cast specified adaptee to authorized adaptee."); } return(await publicDataSource.GetPublicProjectById(id)); } IAuthorizedDataSourceAdaptee authorizedDataSource = adaptee as IAuthorizedDataSourceAdaptee; if (authorizedDataSource == null) { throw new NotSupportedException("Can not cast specified adaptee to authorized adaptee."); } return(await authorizedDataSource.GetProjectById(token, id)); }
/// <summary> /// This method is responsible for return the Oauth url of the data source. /// </summary> /// <returns>This method returns a string containing the Oauth url.</returns> public string GetOauthUrl() { IAuthorizedDataSourceAdaptee authorizedDataSource = adaptee as IAuthorizedDataSourceAdaptee; return(authorizedDataSource?.OauthUrl); }
public async Task <IActionResult> DataProviderCallback(string provider, string code) { IDataSourceAdaptee dataSourceAdaptee; if (Guid.TryParse(provider, out Guid _)) { dataSourceAdaptee = await dataProviderService.RetrieveDataSourceByGuid(provider); } else { dataSourceAdaptee = await dataProviderService.RetrieveDataSourceByName(provider); } if (dataSourceAdaptee == null) { ProblemDetails problem = new ProblemDetails { Title = "Data source not found.", Detail = "Data source could not be found with specified data source guid.", Instance = "5B4E11A6-8209-4F49-B76A-1EF4297D990F" }; return(NotFound(problem)); } IAuthorizedDataSourceAdaptee authorizedDataSourceAdaptee = dataSourceAdaptee as IAuthorizedDataSourceAdaptee; if (authorizedDataSourceAdaptee == null) { ProblemDetails problem = new ProblemDetails { Title = "The specified provider does not allowed authorization.", Detail = "The specified provider is not able to verify the code.", Instance = "EB1F47B2-5526-41F3-8C69-8068F12A92D1" }; return(BadRequest(problem)); } try { OauthTokens tokens = await authorizedDataSourceAdaptee.GetTokens(code); OauthTokensResourceResult resourceResult = mapper.Map <OauthTokens, OauthTokensResourceResult>(tokens); return(Ok(resourceResult)); } catch (NotSupportedByExternalApiException e) { ProblemDetails problem = new ProblemDetails { Title = "External API does not support the functionality from the method.", Detail = e.Message, Instance = "CDFFA448-38B1-450F-8D14-FB89FB7B5462" }; return(BadRequest(problem)); } catch (ExternalException e) { ProblemDetails problem = new ProblemDetails { Title = "An problem encountered while using the external API.", Detail = e.Message, Instance = "7D445CB5-7C19-449C-B9FF-4214E4BE4CF0" }; return(BadRequest(problem)); } catch (NotSupportedException e) { ProblemDetails problem = new ProblemDetails { Title = "The specified data source is not supported.", Detail = e.Message, Instance = "7F2C173E-F001-49CA-8DF8-C18A0837B4AF" }; return(BadRequest(problem)); } }