2
2
3
3
import com .fasterxml .jackson .annotation .JsonInclude ;
4
4
import com .fasterxml .jackson .databind .ObjectMapper ;
5
- import io .github .waileong .fcm .authentication .FcmJwtToken ;
6
- import org .apache .commons .pool2 .impl .GenericObjectPool ;
7
5
import io .github .waileong .fcm .exception .FcmRestClientResponseErrorHandler ;
8
6
import org .springframework .beans .factory .ObjectProvider ;
9
7
import org .springframework .beans .factory .annotation .Qualifier ;
@@ -121,13 +119,11 @@ public FcmRestClientResponseErrorHandler fcmRestClientResponseErrorHandler(
121
119
122
120
/**
123
121
* Configures and provides a {@link RestClient} tailored for FCM communication. This REST client is configured
124
- * with FCM-specific headers, message converters, error handlers, and a token-based authentication mechanism
125
- * leveraging a JWT token pool. It is designed for sending messages to FCM services, using a base URL constructed
122
+ * with FCM-specific headers, message converters, and error handlers. It is designed for sending messages to FCM services, using a base URL constructed
126
123
* from the provided FCM project ID.
127
124
*
128
125
* @param fcmClientHttpRequestFactory The HTTP request factory for FCM.
129
126
* @param fcmMessageConverter The message converter for FCM.
130
- * @param googleFcmJwtTokenPool A pool of JWT tokens for FCM authentication.
131
127
* @param fcmRestClientResponseErrorHandler The error handler for FCM responses.
132
128
* @param fcmProperties Properties containing the FCM credential and project ID.
133
129
* @return A configured {@link RestClient} instance for FCM communication.
@@ -136,7 +132,6 @@ public FcmRestClientResponseErrorHandler fcmRestClientResponseErrorHandler(
136
132
public RestClient fcmRestClient (
137
133
@ Qualifier ("fcmClientHttpRequestFactory" ) ClientHttpRequestFactory fcmClientHttpRequestFactory ,
138
134
@ Qualifier ("fcmMessageConverter" ) MappingJackson2HttpMessageConverter fcmMessageConverter ,
139
- @ Qualifier ("fcmJwtTokenPool" ) GenericObjectPool <FcmJwtToken > googleFcmJwtTokenPool ,
140
135
@ Qualifier ("fcmRestClientResponseErrorHandler" ) FcmRestClientResponseErrorHandler fcmRestClientResponseErrorHandler ,
141
136
FcmProperties fcmProperties ) {
142
137
String projectId = fcmProperties .getCredential ().getProjectId ();
@@ -149,7 +144,6 @@ public RestClient fcmRestClient(
149
144
.baseUrl ("https://fcm.googleapis.com/v1/projects/" + projectId + "/messages:send" )
150
145
.defaultHeader (HttpHeaders .ACCEPT , MediaType .APPLICATION_JSON_VALUE )
151
146
.defaultHeader (HttpHeaders .CONTENT_TYPE , MediaType .APPLICATION_JSON_VALUE )
152
- .defaultHeaders (httpHeaders -> httpHeaders .setBearerAuth (getAccessToken (googleFcmJwtTokenPool )))
153
147
.requestFactory (fcmClientHttpRequestFactory )
154
148
.messageConverters (httpMessageConverters -> {
155
149
// override the default message converters
@@ -160,24 +154,5 @@ public RestClient fcmRestClient(
160
154
.build ();
161
155
}
162
156
163
- /**
164
- * Retrieves an access token from the JWT token pool for authenticating FCM requests. This method ensures
165
- * that a valid token is always used for authentication by borrowing from and returning tokens to the pool.
166
- *
167
- * @param pool The pool of FCM JWT tokens.
168
- * @return A valid JWT token string for FCM authentication.
169
- */
170
- private String getAccessToken (GenericObjectPool <FcmJwtToken > pool ) {
171
- FcmJwtToken fcmJwtToken = null ;
172
- try {
173
- fcmJwtToken = pool .borrowObject ();
174
- return fcmJwtToken .token ();
175
- } catch (Exception e ) {
176
- throw new RuntimeException (e );
177
- } finally {
178
- if (fcmJwtToken != null ) {
179
- pool .returnObject (fcmJwtToken );
180
- }
181
- }
182
- }
157
+
183
158
}
0 commit comments