public static TokenRecord GetNewOAuthToken(TokenRequestModel tr) { RestClient client = new RestSharp.RestClient(tr.TokenURL); var request = new RestRequest(Method.POST); request.AddHeader("Accept", "application/json"); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("client_id", tr.OAuthCreds.ClientId); request.AddParameter("client_secret", tr.OAuthCreds.ClientSecret); if (!String.IsNullOrEmpty(tr.Scope)) { request.AddParameter("scope", "GatewayAccess"); } request.AddParameter("grant_type", "client_credentials"); var tResponse = client.Execute(request); var responseJson = tResponse.Content; TokenModel t = TokenModel.TokenFromJson(responseJson); TokenRecord record = new TokenRecord(t, tr); return(record); }
private static void LogInfo(string message, TokenRequestModel tokenRequest) { //Infrastructure.LoggingService.Information(message, logger, tokenRequest.RequestId); }
//private readonly static NLog.Logger logger; public static TokenModel GetCurrentOAuthToken(TokenRequestModel tokenRequest) { return(GetOAuthToken(tokenRequest)); }
public TokenRecord(TokenModel token, TokenRequestModel request) { Token = token; Expires = DateTime.Now.AddSeconds(token.ExpiresIn); TokenRequest = request; }