private static TokenModel ReNewToken(TokenRecord record) { _ActiveTokenList.Remove(record); record.Token = GetNewOAuthToken(record.TokenRequest); return(record.Token); }
private static TokenModel GetNewOAuthToken(TokenRequestModel tokenRequest) { TokenRecord record = TokenGateway.GetNewOAuthToken(tokenRequest); _ActiveTokenList.Add(record); return(record.Token); }
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); }