2015-10-01 16 views
5

Ho notato che un codice che ho scritto usando SoundcloudPHP ha smesso di autenticarsi oggi, sebbene funzionasse bene l'ultima volta che l'ho usato pochi giorni fa. Per risolvere il problema, ho cercato di autenticare usando l'endpoint/oauth2/token ma la risposta è stata un 401 e un corpo vuoto. Sto usando il ricciolo dalla pagina alla https://developers.soundcloud.com/docs/api/reference#tokensoundcloud/oauth2/token che restituisce solo una risposta 401

Dalla riga di comando:

curl -v -X POST "https://api.soundcloud.com/oauth2/token" -F 'client_id=MY_ID' -F 'client_secret=MY_SECRET' -F 'grant_type=authorization_code' -F 'redirect_uri=MY_REDIRECT' -F 'code=0000000EYAA1CRGodSoKJ9WsdhqVQr3g' 

La risposta:

* About to connect() to api.soundcloud.com port 443 (#0) 
* Trying 72.21.91.127... connected 
* Connected to api.soundcloud.com (72.21.91.127) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: none 
    CApath: /etc/ssl/certs 
* SSLv3, TLS handshake, Client hello (1): 
* SSLv3, TLS handshake, Server hello (2): 
* SSLv3, TLS handshake, CERT (11): 
* SSLv3, TLS handshake, Server finished (14): 
* SSLv3, TLS handshake, Client key exchange (16): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSL connection using AES256-SHA 
* Server certificate: 
* subject: OU=Domain Control Validated; CN=*.soundcloud.com 
* start date: 2014-04-22 16:52:12 GMT 
* expire date: 2016-04-08 10:08:48 GMT 
* subjectAltName: api.soundcloud.com matched 
* issuer: C=BE; O=GlobalSign nv-sa; CN=GlobalSign Domain Validation CA - SHA256 - G2 
* SSL certificate verify ok. 
> POST /oauth2/token HTTP/1.1 
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15 
> Host: api.soundcloud.com 
> Accept: */* 
> Content-Length: 658 
> Expect: 100-continue 
> Content-Type: multipart/form-data; boundary=----------------------------e695cc6c8133 
> 
< HTTP/1.1 100 Continue 
< HTTP/1.1 401 Unauthorized 
< Access-Control-Allow-Headers: Accept, Authorization, Content-Type, Origin 
< Access-Control-Allow-Methods: GET, PUT, POST, DELETE 
< Access-Control-Allow-Origin: * 
< Access-Control-Expose-Headers: Date 
< Cache-Control: private, max-age=0, must-revalidate 
< Date: Thu, 01 Oct 2015 23:25:25 GMT 
< Server: am/2 
< Content-Length: 0 
< 
* Connection #0 to host api.soundcloud.com left intact 
* Closing connection #0 
* SSLv3, TLS alert, Client hello (1): 

Ho creato nuovi tag client per vedere se' lavoro e ottengo la stessa cosa Dal momento che sto usando il ricciolo fornito nei documenti mi aspetto che funzioni. Qualche idea?

+1

Soundcloud ha scritto e dovrebbe essere risolto. – evenodd

risposta

4

Sono il creatore della libreria php https://github.com/njasm/soundcloud.

E gli utenti di esso hanno riportato lo stesso problema, in realtà quello che dici è anche vero che ora, gli esempi di arricciatura su soundcloud non funzionano più (per qualche strano motivo). Inchiesta sul problema per correggere la libreria Ho trovato quello che sembra essere un problema di tipo contenuto.

Sembra che il tipo di contenuto che è necessario utilizzare durante la richiesta/aggiornamento di un token DEVE sempre essere application/x-form-urlencoded e prima che noi (la libreria) funzionassimo correttamente comunicando con un tipo di contenuto di application/json.

Se si è un utente della mia libreria, è necessario eseguire l'aggiornamento all'ultimo master. Se si può aiutare testare la correzione, si prega di riferire alla pagina problema https://github.com/njasm/soundcloud/issues/25

Aggiornamento: È confermato il tipo di contenuto deve essere application/x-form-urlencoded

sto conducendo una certa test per confermare che questo è in realtà il caso. In tal caso, taggare il commit su una versione stabile.

Buona fortuna, e spero che questo aiuti!

+0

Fantastico. Grazie mille. La mia app sta funzionando di nuovo. –

+0

@ self-dealloc nessun problema, felice di aiutare. – njasm

+0

Grazie per la risposta e la correzione! – RustyRamone

0

sono riuscito a risolvere il problema per l'API Soundcloud per Cocoa utilizzando la soluzione da @njsam

su SCSoundCloud.m, aggiungere queste righe:

NSDictionary *customHeaderFields = [NSDictionary dictionaryWithObject:@"application/x-www-form-urlencoded" forKey:@"Content-Type"]; 
[config setObject:customHeaderFields forKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields]; 

il metodo dovrebbe essere come questo:

+ (void)setClientID:(NSString *)aClientID 
     secret:(NSString *)aSecret 
    redirectURL:(NSURL *)aRedirectURL; 
{ 
    NSMutableDictionary *config = [NSMutableDictionary dictionary]; 

    [config setObject:aClientID forKey:kNXOAuth2AccountStoreConfigurationClientID]; 
    [config setObject:aSecret forKey:kNXOAuth2AccountStoreConfigurationSecret]; 
    [config setObject:aRedirectURL forKey:kNXOAuth2AccountStoreConfigurationRedirectURL]; 

    [config setObject:[NSURL URLWithString:kSCSoundCloudAuthURL] forKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL]; 
    [config setObject:[NSURL URLWithString:kSCSoundCloudAccessTokenURL] forKey:kNXOAuth2AccountStoreConfigurationTokenURL]; 
    [config setObject:[NSURL URLWithString:kSCSoundCloudAPIURL] forKey:kSCConfigurationAPIURL]; 
    NSDictionary *customHeaderFields = [NSDictionary dictionaryWithObject:@"application/x-www-form-urlencoded" forKey:@"Content-Type"]; 
    [config setObject:customHeaderFields forKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields]; 

    [[NXOAuth2AccountStore sharedStore] setConfiguration:config forAccountType:kSCAccountType]; 
} 

Inoltre, abbiamo bisogno di aggiornare l'OAuth2Client Biblioteca here di avere il supporto per kNXOAuth2AccountStoreCon figurationCustomHeaderFields

Spero che questo possa aiutare alcune persone per IOS

Problemi correlati