001/* 002 * Copyright 2024 Vonage 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 */ 016package com.vonage.client.auth.camara; 017 018import com.vonage.client.DynamicEndpoint; 019import java.net.URI; 020import java.net.URLEncoder; 021import java.util.Objects; 022import java.util.UUID; 023 024/** 025 * Front-End auth request parameters for the first step in an OAuth2 three-legged check workflow. 026 */ 027public class FrontendAuthRequest extends AuthRequest { 028 029 /** 030 * Creates the parameters for a Front-End Authorization OIDC request. 031 * 032 * @param msisdn The phone number of the user you want to authenticate in E.164 format. 033 * @param redirectUrl The URL to Application's Redirect URI. 034 * @param applicationId The Vonage Application ID. 035 * @param state A unique identifier for the request. This is meant for the client to be able to know which 036 * request it is when it comes back to their redirect_uri. Useful to prevent CSRF attacks. 037 */ 038 public FrontendAuthRequest(String msisdn, URI redirectUrl, UUID applicationId, String state) { 039 super(msisdn, FraudPreventionDetectionScope.NUMBER_VERIFICATION_VERIFY_READ); 040 params.put("client_id", Objects.requireNonNull(applicationId, "Application ID is required.").toString()); 041 params.put("redirect_uri", Objects.requireNonNull(redirectUrl, "Redirect URL is required.").toString()); 042 params.put("response_type", "code"); 043 if (state != null) { 044 params.put("state", state); 045 } 046 } 047 048 public URI buildOidcUrl() { 049 return DynamicEndpoint.buildUri("https://oidc.idp.vonage.com/oauth2/auth", makeParams()); 050 } 051}