package org.zhenchao.passport.oauth.common;

import java.util.Optional;

/**
 * grant type
 *
 * @author zhenchao.wang 2017-02-14 18:11
 * @version 1.0.0
 */
public enum GrantType {

    AUTHORIZATION_CODE("authorization_code"),

    PASSWORD_CREDENTIALS("password"),

    CLIENT_CREDENTIALS("client_credentials");

    private String type;

    GrantType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    /**
     * tell whether {@param grantType} is valid
     *
     * @param grantType
     * @return
     */
    public static boolean isValid(String grantType) {
        return AUTHORIZATION_CODE.getType().equals(grantType) ||
                PASSWORD_CREDENTIALS.getType().equals(grantType) || CLIENT_CREDENTIALS.getType().equals(grantType);
    }

    /**
     * change string param to {@code GrantType} object
     *
     * @param grantType
     * @return
     */
    public static Optional<GrantType> toGrantType(String grantType) {
        for (final GrantType type : GrantType.values()) {
            if (type.getType().equals(grantType)) {
                return Optional.of(type);
            }
        }
        return Optional.empty();
    }
}

@@ -306,16 +306,53 @@
 ntials%22)
+,%0A%0A    REFRESH_TOKEN(%22refresh_token%22)
 ;%0A%0A    p

add refresh_token grant type