All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.breffi.storyclmsdk.OAuth.OAuthAuthenticator Maven / Gradle / Ivy

Go to download

StoryCLM — a digital-platform developed by BREFFI, allowing you to create interactive presentations with immediate feedback on the change in the customer perception of the brand and the representative’s activity.

There is a newer version: 1.0.5
Show newest version
package ru.breffi.storyclmsdk.OAuth;


import java.io.IOException;

import okhttp3.Authenticator;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;

public class OAuthAuthenticator implements Authenticator {

	final private AccessTokenManager accessTokenManager;
    public OAuthAuthenticator(AccessTokenManager accessTokenManager) {
    	this.accessTokenManager = accessTokenManager;
		// TODO Auto-generated constructor stub
	}

	private static int responseCount(Response response) {
        int result = 1;
        while ((response = response.priorResponse()) != null) {
            result++;
        }
        return result;
    }
    
	
	
	@Override
	public Request authenticate(Route route, Response response) throws IOException {
			  if(responseCount(response) >= 3) {
				  return null;
			  }
			  
              if(responseCount(response) >= 2) {
                  // If both the original call and the call with refreshed token failed,
                  // it will probably keep failing, so don't try again.
                  accessTokenManager.checkAndReturnAuthEntityAsync(true).execute();
              }
              return response.request().newBuilder()
                              .header("Authorization", accessTokenManager.getTokenType() + " " + accessTokenManager.getAccessToken())
                              .build();
	}
	

	
	}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy