// Path: soap-server/src/main/java/com/cookbook/tutorial/service/Constants.java
// public class Constants {
//     public static final String DEFAULT_TOKEN = "ASD9807123#123POI";
// }


import com.cookbook.tutorial.service.Constants;
import org.mule.module.http.internal.ParameterMap;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Map;
package com.cookbook.tutorial;



@Path("/oauth")
public class MuleAuthorizeResource {

    @GET
    @Path("/authorize")
    @Produces(MediaType.APPLICATION_JSON)
    public Response authorize(@QueryParam("client_id") String accountId, @QueryParam("redirect_uri") String redirectTo) {

        if (CLIENT_ID.equals(accountId)) {
            return Response.status(302).location(
                    UriBuilder.fromUri(redirectTo).queryParam("code", new String[] { CODE }).build()).build();
        } else {
            return Response.status(400).entity(
                    UriBuilder.fromUri(redirectTo).queryParam("error", new String[] { "invalid_client" }).build()).build();
        }
    }

    @POST
    @Path("/accessToken")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public Response token(InputStream params) {
        try {

            ObjectInputStream objectReader = new ObjectInputStream(params);
            ParameterMap parameterMap = (ParameterMap)objectReader.readObject();

            if (parameterMap.get("code").equals(CODE) &&
                    parameterMap.get("client_id").equals(CLIENT_ID) &&
                    parameterMap.get("client_secret").equals(CLIENT_SECRET)
                    ) {
                Map<String, Object> map = new HashMap<>();
// Path: soap-server/src/main/java/com/cookbook/tutorial/service/Constants.java
// public class Constants {
//     public static final String DEFAULT_TOKEN = "ASD9807123#123POI";
// }


// Path: rest-server/src/main/java/com/cookbook/tutorial/MuleAuthorizeResource.java
import com.cookbook.tutorial.service.Constants;
import org.mule.module.http.internal.ParameterMap;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Map;

package com.cookbook.tutorial;



@Path("/oauth")
public class MuleAuthorizeResource {

    @GET
    @Path("/authorize")
    @Produces(MediaType.APPLICATION_JSON)
    public Response authorize(@QueryParam("client_id") String accountId, @QueryParam("redirect_uri") String redirectTo) {

        if (CLIENT_ID.equals(accountId)) {
            return Response.status(302).location(
                    UriBuilder.fromUri(redirectTo).queryParam("code", new String[] { CODE }).build()).build();
        } else {
            return Response.status(400).entity(
                    UriBuilder.fromUri(redirectTo).queryParam("error", new String[] { "invalid_client" }).build()).build();
        }
    }

    @POST
    @Path("/accessToken")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public Response token(InputStream params) {
        try {

            ObjectInputStream objectReader = new ObjectInputStream(params);
            ParameterMap parameterMap = (ParameterMap)objectReader.readObject();

            if (parameterMap.get("code").equals(CODE) &&
                    parameterMap.get("client_id").equals(CLIENT_ID) &&
                    parameterMap.get("client_secret").equals(CLIENT_SECRET)
                    ) {
                Map<String, Object> map = new HashMap<>();
                map.put("access_token", Constants.DEFAULT_TOKEN);