44import com .azure .core .credential .TokenCredential ;
55import com .azure .core .credential .TokenRequestContext ;
66import com .microsoft .graph .exceptions .AuthenticationException ;
7- import com .microsoft .graph .exceptions .Error ;
8- import com .microsoft .graph .exceptions .ErrorConstants ;
9- import com .microsoft .graph .httpcore .IHttpRequest ;
7+ import com .microsoft .graph .http .IHttpRequest ;
108import okhttp3 .Request ;
11- import com .microsoft .graph .exceptions .ErrorConstants .*;
129
1310import java .net .MalformedURLException ;
1411import java .net .URL ;
2017
2118import javax .annotation .Nonnull ;
2219
20+ /**
21+ * An implementation of the Authentication Provider with Azure-identity
22+ */
2323public class TokenCredentialAuthProvider implements IAuthenticationProvider <Request > {
2424
2525 //TokenCredential expected from user
@@ -40,9 +40,7 @@ public class TokenCredentialAuthProvider implements IAuthenticationProvider<Requ
4040 */
4141 public TokenCredentialAuthProvider (@ Nonnull final TokenCredential tokenCredential ) throws AuthenticationException {
4242 if (tokenCredential == null ) {
43- throw new AuthenticationException (new Error (Codes .InvalidArgument ,
44- String .format (Messages .NullParameter , "TokenCredential" ))
45- ,new IllegalArgumentException ());
43+ throw new AuthenticationException (new IllegalArgumentException ("tokenCredential parameter cannot be null." ));
4644 }
4745
4846 this .tokenCredential = tokenCredential ;
@@ -127,7 +125,7 @@ private String getAccessToken() throws AuthenticationException {
127125 final AccessToken token = this .tokenCredential .getToken (this .context ).block (this .tokenBlockTimeout );
128126 return token .getToken ();
129127 } catch (RuntimeException e ) {
130- throw new AuthenticationException (new Error ( ErrorConstants . Codes . GeneralException , ErrorConstants . Messages . AuthTimeOut ) , e );
128+ throw new AuthenticationException ("Authentication failed or timed out." , e );
131129 }
132130 }
133131}
0 commit comments