001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk.pkce; 019 020 021import com.nimbusds.oauth2.sdk.id.Identifier; 022import net.jcip.annotations.Immutable; 023 024 025/** 026 * Method that was used to derive an authorisation code challenge. 027 * 028 * <p>Related specifications: 029 * 030 * <ul> 031 * <li>Proof Key for Code Exchange by OAuth Public Clients (RFC 7636) 032 * </ul> 033 */ 034@Immutable 035public final class CodeChallengeMethod extends Identifier { 036 037 038 private static final long serialVersionUID = -8125202768444965372L; 039 040 041 /** 042 * Plain code challenge method. 043 */ 044 public static final CodeChallengeMethod PLAIN = new CodeChallengeMethod("plain"); 045 046 047 /** 048 * SHA-256 code challenge method. 049 */ 050 public static final CodeChallengeMethod S256 = new CodeChallengeMethod("S256"); 051 052 053 /** 054 * Gets the default code challenge method. 055 * 056 * @return {@link #PLAIN} 057 */ 058 public static CodeChallengeMethod getDefault() { 059 060 return PLAIN; 061 } 062 063 064 /** 065 * 066 * @param value The code challenge method value. Must not be 067 * {@code null} or empty string. 068 */ 069 public CodeChallengeMethod(final String value) { 070 071 super(value); 072 } 073 074 075 /** 076 * Parses a code challenge method from the specified value. 077 * 078 * @param value The code challenge method value. Must not be 079 * {@code null} or empty string. 080 * 081 * @return The code challenge method. 082 */ 083 public static CodeChallengeMethod parse(final String value) { 084 085 if (value.equals(PLAIN.getValue())) { 086 return PLAIN; 087 } else if (value.equals(S256.getValue())) { 088 return S256; 089 } else { 090 return new CodeChallengeMethod(value); 091 } 092 } 093 094 095 @Override 096 public boolean equals(final Object object) { 097 098 return object instanceof CodeChallengeMethod && 099 this.toString().equals(object.toString()); 100 } 101}