Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from artwist/master

Credentials flow
  • Loading branch information...
commit ee15265e1535509bf4104652e63df71c564ec2b8 2 parents edb43c3 + f272380
@mptre authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 Services/Soundcloud.php
View
35 Services/Soundcloud.php
@@ -271,6 +271,41 @@ function getAccessTokenUrl($params = array())
}
/**
+ * Retrieve access token through credentials flow
+ *
+ * @param string $username Username
+ * @param string $password Password
+ *
+ * @return mixed
+ *
+ * @access public
+ */
+ function credentialsFlow($username, $password)
+ {
+ $postData = array(
+ 'client_id' => $this->_clientId,
+ 'client_secret' => $this->_clientSecret,
+ 'username' => $username,
+ 'password' => $password,
+ 'grant_type' => 'password'
+ );
+
+ $options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData);
+ $response = json_decode(
+ $this->_request($this->getAccessTokenUrl(), $options),
+ true
+ );
+
+ if (array_key_exists('access_token', $response)) {
+ $this->_accessToken = $response['access_token'];
+
+ return $response;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Retrieve access token
*
* @param string $code Optional OAuth code returned from the service provider
Please sign in to comment.
Something went wrong with that request. Please try again.