async Task <IAuthenticationToken> GetAuthToken() { var twoLeggedApi = new TwoLeggedApi(); ApiResponse <dynamic> apiResponse; try { apiResponse = await twoLeggedApi.AuthenticateAsyncWithHttpInfo(_clientId, _clientSecret, oAuthConstants.CLIENT_CREDENTIALS, new[] { Scope.BucketRead, Scope.BucketCreate, Scope.DataRead, Scope.DataWrite }); if (apiResponse == null) { _logger.Log(LogType.Error, "NULL API response during authorization"); return(null); } if (apiResponse.StatusCode != 200) { _logger.Log(LogType.Error, "API response not expected during authorization: " + apiResponse.StatusCode); return(null); } Configuration.Default.AccessToken = apiResponse.Data.access_token; } catch (Exception e) { _logger.Log(LogType.Error, "Exception while attempting to get access token: " + e); return(null); } return(new AuthenticationToken(apiResponse.Data.access_token, apiResponse.Data.expires_in)); }
private async Task <ApiResponse <dynamic> > oauthExecAsync() { try { _2LEGGED = ""; TwoLeggedApi _twoLeggedApi = new TwoLeggedApi(); ApiResponse <dynamic> bearer = await _twoLeggedApi.AuthenticateAsyncWithHttpInfo( FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, oAuthConstants.CLIENT_CREDENTIALS, _scope); httpErrorHandler(bearer, "Failed to get your token"); _2LEGGED = bearer.Data.access_token; return(bearer); } catch (Exception ex) { MessageBox.Show("Exception when calling TwoLeggedApi.AuthenticateAsyncWithHttpInfo : " + ex.Message, APP_NAME, MessageBoxButton.OK, MessageBoxImage.Error); return(null); } }
private async Task <Token> RefreshForgeToken(IAsyncCollector <Token> tokenTable, ILogger log) { // Call the asynchronous version of the 2-legged client with HTTP information // HTTP information will help you to verify if the call was successful as well // as read the HTTP transaction headers. ApiResponse <dynamic> response = await _twoLeggedApi.AuthenticateAsyncWithHttpInfo(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, oAuthConstants.CLIENT_CREDENTIALS, _scope); ForgeToken forgeToken = (response.Data as DynamicJsonResponse).ToObject <ForgeToken>(); Token token = new Token(); token.ForgeToken = forgeToken; await tokenTable.AddAsync(token); log.LogInformation("C# timer trigger function SaveForgeToken saved a Forge Token"); return(token); }
private async Task <string> _2leggedAsync() { _logger.LogInformation("Refreshing Forge token"); // Call the asynchronous version of the 2-legged client with HTTP information // HTTP information helps to verify if the call was successful as well as read the HTTP transaction headers. var twoLeggedApi = new TwoLeggedApi(); Autodesk.Forge.Client.ApiResponse <dynamic> response = await twoLeggedApi.AuthenticateAsyncWithHttpInfo(Configuration.ClientId, Configuration.ClientSecret, oAuthConstants.CLIENT_CREDENTIALS, _scope); if (response.StatusCode != StatusCodes.Status200OK) { throw new Exception("Request failed! (with HTTP response " + response.StatusCode + ")"); } // The JSON response from the oAuth server is the Data variable and has already been parsed into a DynamicDictionary object. dynamic bearer = response.Data; return(bearer.access_token); }
private async static Task <ApiResponse <dynamic> > oauthExecAsync() { try { AccessToken = ""; TwoLeggedApi _twoLeggedApi = new TwoLeggedApi(); ApiResponse <dynamic> bearer = await _twoLeggedApi.AuthenticateAsyncWithHttpInfo( FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, oAuthConstants.CLIENT_CREDENTIALS, SCOPES); httpErrorHandler(bearer, "Failed to get your token"); AccessToken = bearer.Data.access_token; BucketAPI.Configuration.AccessToken = AccessToken; ObjectsAPI.Configuration.AccessToken = AccessToken; USDerivativesAPI.Configuration.AccessToken = AccessToken; EMEADerivativesAPI.Configuration.AccessToken = AccessToken; return(bearer); } catch (Exception ex) { Console.WriteLine("Exception when calling TwoLeggedApi.AuthenticateAsyncWithHttpInfo : " + ex.Message); return(null); } }
protected override void OnStart(string[] args) { string clientID = "Dm1AJ95famLKnf4MUOGpwO7zJIcBF4J7"; string clientSecret = "vAyaauIpMr4qhy6O"; TwoLeggedApi _twoLeggedApi = new TwoLeggedApi(); Task <ApiResponse <dynamic> > retorno = _twoLeggedApi.AuthenticateAsyncWithHttpInfo(clientID, clientSecret, oAuthConstants.CLIENT_CREDENTIALS, new Scope[] { Scope.DataRead, Scope.DataCreate, Scope.DataWrite, Scope.ViewablesRead }); if (retorno.Result.StatusCode < 200 || retorno.Result.StatusCode >= 300) { throw new Exception("Erro de CONEXAO"); } token = retorno.Result.Data.access_token; UploadAsync().GetAwaiter().GetResult(); string filename = CheckFileExists(); File.AppendAllText(filename, $"{DateTime.Now} started.{Environment.NewLine}"); }