6565 * Typical use, discovering everything from the QuestDB server:
6666 * <pre>{@code
6767 * try (OidcDeviceAuth auth = OidcDeviceAuth.fromQuestDB("https://questdb.example.com:9000")) {
68- * String token = auth.getToken (); // signs in on first use, then caches and refreshes
68+ * String token = auth.signIn (); // signs in on first use, then caches and refreshes
6969 * // ... use token as an HTTP Bearer header or a PG-wire _sso password ...
7070 * }
7171 * }</pre>
7979 * .groupsInToken(true)
8080 * .build();
8181 * }</pre>
82- * {@link #getToken ()} serves a cached token while valid, silently refreshes when a refresh token
82+ * {@link #signIn ()} serves a cached token while valid, silently refreshes when a refresh token
8383 * exists, otherwise re-runs the interactive flow. An instance lock serializes calls, so two
8484 * sign-ins never start at once. A sign-in waiting for the user holds that lock for the device code
85- * lifetime (up to 30 minutes), so a concurrent {@link #getToken ()} or {@link #clearCache()} blocks
86- * behind it - but {@link #getTokenSilently ()} never waits: it fails fast with an
85+ * lifetime (up to 30 minutes), so a concurrent {@link #signIn ()} or {@link #clearCache()} blocks
86+ * behind it - but {@link #getToken ()} never waits: it fails fast with an
8787 * {@link OidcAuthException} so a request/flush path never stalls. To abort a waiting sign-in, call
8888 * {@link #close()} from another thread; it signals the flow to stop, which then fails with an
8989 * {@link OidcAuthException} rather than polling until the device code expires. Cancellation is seen
@@ -153,8 +153,8 @@ public class OidcDeviceAuth implements QuietCloseable {
153153 private final StringSink formSink = new StringSink ();
154154 private final boolean groupsInToken ;
155155 private final int httpTimeoutMillis ;
156- // serializes getToken ()/getTokenSilently ()/clearCache()/close(); getToken () holds it for the whole
157- // interactive flow, getTokenSilently () uses tryLock so the flush path never stalls behind a sign-in
156+ // serializes signIn ()/getToken ()/clearCache()/close(); signIn () holds it for the whole
157+ // interactive flow, getToken () uses tryLock so the flush path never stalls behind a sign-in
158158 private final ReentrantLock lock = new ReentrantLock ();
159159 private final DeviceCodePrompt prompt ;
160160 private final StringSink responseStatus = new StringSink ();
@@ -351,7 +351,7 @@ public static OidcDeviceAuth fromQuestDB(String questdbUrl, DiscoveryOptions opt
351351 }
352352
353353 /**
354- * Drops any cached token so the next {@link #getToken ()} starts a fresh interactive sign-in.
354+ * Drops any cached token so the next {@link #signIn ()} starts a fresh interactive sign-in.
355355 */
356356 public void clearCache () {
357357 lock .lock ();
@@ -368,7 +368,7 @@ public void clearCache() {
368368 }
369369
370370 /**
371- * Frees the network connections and native buffers this instance holds. If a {@link #getToken ()}
371+ * Frees the network connections and native buffers this instance holds. If a {@link #signIn ()}
372372 * sign-in is in flight on another thread, signals it to stop so it fails with an
373373 * {@link OidcAuthException} instead of polling until the device code expires. The signal is observed
374374 * between polls (within ~100ms while waiting out a poll interval); a poll request already in flight
@@ -378,12 +378,12 @@ public void clearCache() {
378378 * {@link DeviceCodePrompt} that blocks in {@code promptUser} - for example the default
379379 * {@link DeviceCodePrompt#openBrowser()} prompt while it hands the verification URL to the OS browser,
380380 * which is not bounded by the HTTP timeout: the flow holds the lock across that one-off prompt, so a
381- * racing {@code close()} waits it out too. Idempotent. After close, {@link #getToken ()} and
382- * {@link #clearCache()} throw.
381+ * racing {@code close()} waits it out too. Idempotent. After close, {@link #signIn ()},
382+ * {@link #getToken()} and {@link # clearCache()} throw.
383383 */
384384 @ Override
385385 public void close () {
386- // flag cancellation before taking the lock: getToken () holds it for the whole flow, so signal the
386+ // flag cancellation before taking the lock: signIn () holds it for the whole flow, so signal the
387387 // in-flight sign-in to stop via a lock-free volatile write, then acquire the lock - released by the
388388 // cancelled flow once it observes the flag (between polls, or after an in-flight poll returns) - and
389389 // free the native resources. close() never frees while a flow holds the lock, so no use-after-free
@@ -399,11 +399,11 @@ public void close() {
399399 }
400400
401401 /**
402- * @return {@code "Bearer " + getToken ()}, ready to use as the value of an HTTP
402+ * @return {@code "Bearer " + signIn ()}, ready to use as the value of an HTTP
403403 * {@code Authorization} header.
404404 */
405405 public String getAuthorizationHeaderValue () {
406- return "Bearer " + getToken ();
406+ return "Bearer " + signIn ();
407407 }
408408
409409 /**
@@ -415,11 +415,11 @@ public String getAuthorizationHeaderValue() {
415415 * @throws OidcAuthException if the interactive flow fails, times out, or the identity provider
416416 * does not return the expected token
417417 */
418- public String getToken () {
418+ public String signIn () {
419419 lock .lock ();
420420 try {
421421 throwIfClosed ();
422- // only the kind of token getToken () actually serves counts as a cache hit; a grant that
422+ // only the kind of token signIn () actually serves counts as a cache hit; a grant that
423423 // returned the other kind (access token when the server wants the id token, or vice versa)
424424 // leaves the served token null, so re-run the flow rather than report the unusable grant as
425425 // valid and have selectToken() throw on this and every later call
@@ -440,13 +440,13 @@ public String getToken() {
440440 }
441441
442442 /**
443- * Like {@link #getToken ()} but never starts the interactive device flow, never prompts, and never waits
443+ * Like {@link #signIn ()} but never starts the interactive device flow, never prompts, and never waits
444444 * on interactive input: returns the cached token while valid, silently refreshes when a refresh token is
445445 * available, otherwise throws. Designed for the request/flush path of a long-lived client, for example
446- * {@code Sender.builder(...).httpTokenProvider(auth::getTokenSilently )}, where an interactive prompt is
447- * inappropriate. Call {@link #getToken ()} once to sign in first.
446+ * {@code Sender.builder(...).httpTokenProvider(auth::getToken )}, where an interactive prompt is
447+ * inappropriate. Call {@link #signIn ()} once to sign in first.
448448 * <p>
449- * It does not wait behind an interactive {@link #getToken ()} running on another thread (which would stall
449+ * It does not wait behind an interactive {@link #signIn ()} running on another thread (which would stall
450450 * the flush for the whole device-code lifetime): if such a sign-in holds the lock it fails fast, and the
451451 * caller should retry once the sign-in completes. It is not, however, instantaneous - when the cached
452452 * token has expired it makes one synchronous refresh round-trip to the token endpoint, bounded by
@@ -458,9 +458,9 @@ public String getToken() {
458458 * not be refreshed without an interactive sign-in, or if a sign-in or
459459 * refresh is already in progress on another thread
460460 */
461- public String getTokenSilently () {
461+ public String getToken () {
462462 throwIfClosed ();
463- // never wait on the flush path: getToken ()'s sign-in holds the lock for the whole device-code
463+ // never wait on the flush path: signIn ()'s sign-in holds the lock for the whole device-code
464464 // lifetime (up to 30 minutes), so tryLock and fail fast if held. A sign-in in progress means there
465465 // is no token to serve yet, so the caller gets a prompt exception to retry rather than a stalled
466466 // flush
@@ -477,9 +477,9 @@ public String getTokenSilently() {
477477 if (refreshToken != null && tryRefresh ()) {
478478 return selectToken ();
479479 }
480- throw new OidcAuthException ("the cached token expired and could not be refreshed without an interactive sign-in; call getToken () to sign in again" );
480+ throw new OidcAuthException ("the cached token expired and could not be refreshed without an interactive sign-in; call signIn () to sign in again" );
481481 }
482- throw new OidcAuthException ("no token has been obtained yet; call getToken () to sign in before using getTokenSilently ()" );
482+ throw new OidcAuthException ("no token has been obtained yet; call signIn () to sign in before using getToken ()" );
483483 } finally {
484484 lock .unlock ();
485485 }
0 commit comments