001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.oauth; 018 019import org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.Immutable; 022import java.net.URI; 023 024import static java.util.Objects.requireNonNull; 025 026/** 027 * A browser redirect and its pending authorization. The authorization URI contains transient state and must not be 028 * logged. Store or seal the pending object before sending the redirect. Applications set and clear cookies. 029 * 030 * @author <a href="https://www.revetkn.com">Mark Allen</a> 031 * @since 1.0.0 032 */ 033@Immutable 034public final class AuthorizationRedirect { 035 private final @NonNull URI authorizationUri; 036 private final @NonNull PendingAuthorization pendingAuthorization; 037 038 AuthorizationRedirect(@NonNull URI authorizationUri, @NonNull PendingAuthorization pendingAuthorization) { 039 this.authorizationUri = requireNonNull(authorizationUri); 040 this.pendingAuthorization = requireNonNull(pendingAuthorization); 041 } 042 043 /** 044 * Returns the browser redirect URI, including state and PKCE challenge. 045 * 046 * @return the URI 047 * @since 1.0.0 048 */ 049 public @NonNull URI getAuthorizationUri() { return this.authorizationUri; } 050 051 /** 052 * Returns the pending authorization to seal or store. 053 * 054 * @return pending authorization 055 * @since 1.0.0 056 */ 057 public @NonNull PendingAuthorization getPendingAuthorization() { return this.pendingAuthorization; } 058 059 /** 060 * Returns an optional per-flow cookie name. The suffix selects a cookie, not authenticates it. 061 * 062 * @return cookie name 063 * @since 1.0.0 064 */ 065 public @NonNull String getPerFlowCookieName() { 066 return OAuthCookieNames.fromState(this.pendingAuthorization.state()); 067 } 068 069 /** 070 * Redacts the authorization URI and pending secrets. 071 * 072 * @return a redacted description 073 * @since 1.0.0 074 */ 075 @Override 076 public @NonNull String toString() { return "AuthorizationRedirect{uri=<redacted>}"; } 077}