2016-01-29 47 views
6

Sto utilizzando Postman per testare OAuth 2 da un'installazione AEM vaniglia.403 Risposta da Adobe Experience Manager OAuth 2 Token Endpoint

enter image description here

Postman possono ottenere con successo il codice di autorizzazione da/OAuth/autorizzare dopo Garantisco accesso:

enter image description here

Ma quando si tenta di utilizzare il codice per ottenere un token da/OAuth/token riceve la seguente risposta:

HTTP ERROR: 403 Problem accessing /oauth/token. Reason: Forbidden Powered by Jetty://

Guardare in Fiddler che sta facendo un post a/OAuth/token con il seguente nome/Valori nel corpo:

client_id: Client ID from /libs/granite/oauth/content/client.html

client_secret: Client Secret from /libs/granite/oauth/content/client.html

redirect_uri: https://www.getpostman.com/oauth2/callback

grant_type: authorization_code

code: Code returned from previous request to oauth/authorize

mi sto perdendo qualcosa?

risposta

1

ho trovato la risposta me stesso e ho pensato di condividere il processo che ho seguito così come la risposta perché potrebbe aiutare altre persone nuove in AEM.

come trovare la causa dell'errore:

  1. Vai a CRXDE Lite.
  2. Seleziona console.
  3. Quindi deselezionare il pulsante di arresto per consentire la visualizzazione di nuovi registri console (questo è molto contro-intuitivo per me).

CRXDE Lite Console

Da qui sono stato in grado di vedere la causa del problema:

org.apache.sling.security.impl.ReferrerFilter Rejected empty referrer header for POST request to /oauth/token

Perché postino non pone un referrer nell'intestazione della richiesta ho dovuto dire Apache Sling per consentire intestazioni di richieste vuote.

Per fare questo:

  1. Vai a/Sistema/console/ConfigMgr
  2. Aprire l'Apache Sling Referente Filtro Config
  3. Selezionare la casella di controllo Consenti vuota

Apache Sling Referrer Filter Config

1

Sarebbe utile se fosse possibile elencare alcuni frammenti di codice su come si sta creando l'URL e recuperando il token.

Ecco un esempio di come abbiamo implementato molto simile a quello che stai cercando di fare, forse sarà d'aiuto.

definire un servizio come qui di seguito (frammento) e definire i valori (host, url, ecc) in OSGi (o si può anche difficile loro codice a scopo di test)

 @Service(value = OauthAuthentication.class) 
    @Component(immediate = true, label = "My Oauth Authentication", description = "My Oauth Authentication", policy = ConfigurationPolicy.REQUIRE, metatype = true) 
    @Properties({ 
     @Property(name = Constants.SERVICE_VENDOR, value = "ABC"), 
     @Property(name = "service.oauth.host", value = "", label = "Oauth Host", description = "Oauth Athentication Server"), 
     @Property(name = "service.oauth.url", value = "/service/oauth/token", label = "Oauth URL", description = "Oauth Authentication URL relative to the host"), 
     @Property(name = "service.oauth.clientid", value = "", label = "Oauth Client ID", description = "Oauth client ID to use in the authentication procedure"), 
     @Property(name = "service.oauth.clientsecret", value = "", label = "Oauth Client Secret", description = "Oauth client secret to use in the authentication procedure"), 
     @Property(name = "service.oauth.granttype", value = "", label = "Oauth Grant Type", description = "Oauth grant type") }) 
     public class OauthAuthentication { 
     ... 
     @Activate 
     private void activate(ComponentContext context) { 
     Dictionary<String, Object> properties = context.getProperties(); 
     host = OsgiUtil.toString(properties, PROPERTY_SERVICE_OAUTH_HOST,new String()); 

     // Similarly get all values 
     url = 
     clientID = 
     clientSecret = 
     grantType = 
     authType = "Basic" + " "+ Base64.encode(new String(clientID + ":" + clientSecret)); 
     } 

     public static void getAuthorizationToken(
     try { 
      UserManager userManager = resourceResolver.adaptTo(UserManager.class); 
      Session session = resourceResolver.adaptTo(Session.class); 

      // Getting the current user       
      Authorizable auth = userManager.getAuthorizable(session.getUserID()); 

     user = auth.getID(); 
     password = ... 
     ... 
     ... 
     String serviceURL = (host.startsWith("http") ? "": protocol + "://") + host + url; 
     httpclient = HttpClients.custom().build(); 
     HttpPost httppost = new HttpPost(serviceURL); 

     // set params 
     ArrayList<BasicNameValuePair> formparams = new ArrayList<BasicNameValuePair>(); 
     formparams.add(new BasicNameValuePair("username", user)); 
     formparams.add(new BasicNameValuePair("password", password)); 
     formparams.add(new BasicNameValuePair("client_id", clientID)); 
     formparams.add(new BasicNameValuePair("client_secret",clientSecret)); 
     formparams.add(new BasicNameValuePair("grant_type",grantType)); 

      UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); 
      httppost.setEntity(postEntity); 

      // set header 
      httppost.addHeader("Authorization", authType); 
      response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 

      if (response.getStatusLine().getStatusCode() == 200) { 
      if (entity != null) { 
       object = new JSONObject(EntityUtils.toString(entity)); 
      } 
      if (object != null) { 
       accessToken = object.getString("access_token"); 
       //// 
      } 
      } 
     } 
+0

Grazie per la risposta. Sto utilizzando la funzionalità di Oauth in Postman per creare gli URL e recuperare il token che puoi scaricare gratuitamente da [qui] (https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=it). Se esegui un'installazione vaniglia di AEM 6.1 e aggiungi un nuovo client Oauth e quindi utilizzi i dettagli del client in Postman, avrai ricreato il mio scenario. Vengo da uno sfondo .NET, quindi ho provato a creare un client .NET ma ho anche restituito un 403 quando provo a postare su/oauth/token. – GerardBeckerleg

+0

Forse ho frainteso. Puoi provare l'url sull'ambiente Publish (4503), vedere se fa alcuna differenza. –

+0

Lo stesso problema durante l'esecuzione nell'ambiente Publish (4503). – GerardBeckerleg

0

Un buon modo per consentire di elencare gli host consentiti, altrimenti questo è contro b pratiche estese per la lista di controllo della sicurezza AEM.

La sua multa per l'ambiente di sviluppo non per la produzione.