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 /** 039 * Plain code challenge method. 040 */ 041 public static final CodeChallengeMethod PLAIN = new CodeChallengeMethod("plain"); 042 043 044 /** 045 * SHA-256 code challenge method. 046 */ 047 public static final CodeChallengeMethod S256 = new CodeChallengeMethod("S256"); 048 049 050 /** 051 * Gets the default code challenge method. 052 * 053 * @return {@link #PLAIN} 054 */ 055 public static CodeChallengeMethod getDefault() { 056 057 return PLAIN; 058 } 059 060 061 /** 062 * 063 * @param value The code challenge method value. Must not be 064 * {@code null} or empty string. 065 */ 066 public CodeChallengeMethod(final String value) { 067 068 super(value); 069 } 070 071 072 /** 073 * Parses a code challenge method from the specified value. 074 * 075 * @param value The code challenge method value. Must not be 076 * {@code null} or empty string. 077 * 078 * @return The code challenge method. 079 */ 080 public static CodeChallengeMethod parse(final String value) { 081 082 if (value.equals(PLAIN.getValue())) { 083 return PLAIN; 084 } else if (value.equals(S256.getValue())) { 085 return S256; 086 } else { 087 return new CodeChallengeMethod(value); 088 } 089 } 090 091 092 @Override 093 public boolean equals(final Object object) { 094 095 return object instanceof CodeChallengeMethod && 096 this.toString().equals(object.toString()); 097 } 098}