Package org.apache.sling.auth.oauth_client

# Class OAuthTokenResponse

java.lang.Object
org.apache.sling.auth.oauth_client.OAuthTokenResponse

@NotNull public class OAuthTokenResponse extends Object
Encapsulates the response to a token request.

This class has two top-level states:

1. has a valid access token: `hasValidToken()` returns `true`, and `getTokenValue()` returns the token value.
2. does not have a valid access token: `hasValidToken()` returns `false`, and `getRedirectUri()` returns the URI to redirect the user to.

Methods generally throw `IllegalStateException` if they are called in an unexpected state and do not return null values.

## Constructor Summary

Constructors
Constructor
Description
`OAuthTokenResponse(@NotNull Optional<String> token, @NotNull ClientConnection connection, @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull String redirectPath)`

## Method Summary

Modifier and Type
Method
Description
`@NotNull URI`
`getRedirectUri()`
Returns the URI to redirect the user to in order to start the OAuth flow
`@NotNull String`
`getTokenValue()`
Returns a valid access token value and throws an `IllegalStateException` otherwise
`boolean`
`hasValidToken()`
Returns true if a valid access token is present and false otherwise

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### OAuthTokenResponse

public OAuthTokenResponse(@NotNull @NotNull Optional<String> token, @NotNull @NotNull ClientConnection connection, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull String redirectPath)

## Method Details

### hasValidToken

public boolean hasValidToken()
Returns true if a valid access token is present and false otherwise

Returns:
  true if a valid access token is present

### getTokenValue

@NotNull public @NotNull String getTokenValue()
Returns a valid access token value and throws an `IllegalStateException` otherwise

Returns:
  a valid access token value
Throws:
  `IllegalStateException` - if no access token is present

### getRedirectUri

@NotNull public @NotNull URI getRedirectUri()
Returns the URI to redirect the user to in order to start the OAuth flow

Returns:
  the URI to redirect the user to
Throws:
  `IllegalStateException` - if an access token is present