Skip to content

Instantly share code, notes, and snippets.

@jeffwysong
Last active December 18, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffwysong/5834865 to your computer and use it in GitHub Desktop.
Save jeffwysong/5834865 to your computer and use it in GitHub Desktop.
import com.stormpath.sdk.account.Account;
import com.stormpath.sdk.application.Application;
import com.stormpath.sdk.authc.UsernamePasswordRequest;
import com.stormpath.sdk.client.Client;
import com.stormpath.sdk.client.DefaultApiKey;
...
String applicationUrl = System.getenv("STORMPATH_URL");
String apiKeyId = System.getenv("STORMPATH_API_KEY_ID");
String apiKeySecret = System.getenv("STORMPATH_API_KEY_SECRET");
Client client = new Client(new DefaultApiKey(apiKeyId, apiKeySecret));
Application application = client.getDataStore().getResource(applicationUrl, Application.class);
/*
To authenticate an account you must have the application the account authenticates against.
With the application, the account is authenticated by providing the username and password as follows:
Note: this sample code assumes an account with username "johnsmith" and password "4P@$$w0rd!"
exists in your application directory
*/
UsernamePasswordRequest request = new UsernamePasswordRequest("johnsmith", "4P@$$w0rd!");
Account loggedInAccount = application.authenticateAccount(request).getAccount();
...
require 'stormpath-sdk'
application_url = ENV['STORMPATH_URL']
apiKeyId = ENV['STORMPATH_API_KEY_ID']
apiKeySecret = ENV['STORMPATH_API_KEY_SECRET']
api_key = Stormpath::ApiKey.new apiKeyId, apiKeySecret
client = Stormpath::Client.new api_key: api_key
application = client.applications.get application_url
#To authenticate an account you must have the application the account authenticates against.
#With the application, the account is authenticated by providing the username and password as follows:
#Note: this sample code assumes an account with username "johnsmith" and password "4P@$$w0rd!"
# exists in your application directory
auth_request = Stormpath::Authentication::UsernamePasswordRequest.new 'johnsmith', '4P@$$w0rd!'
auth_result = application.authenticate_account auth_request
account = auth_result.account
...
<div>
<ol>
<li><span class="step">Download the SDK:</span> Download the official Stormpath Ruby, Java, Python or PHP
<a href="http://www.stormpath.com/docs">developer SDK</a> for your programming language. These SDKs are full REST clients that will interact with the Stormpath REST API automatically.</li>
<li><p><span class="step">Access and Use Your Application:</span> Use the STORMPATH_URL from your Heroku application's environment variables and access your Stormpath Application instance:</p>
<p>
<span>Ruby Example:</span>
<script src="https://gist.github.com/jeffwysong/5834865.js?file=ruby-sample.rb"></script>
</p>
<p>
<span>Java Example:</span>
<script src="https://gist.github.com/jeffwysong/5834865.js?file=java-example.java"></script>
</p>
</li>
</ol>
</div>
@josebarrueta
Copy link

Please update your gist with the contents from:

https://gist.github.com/josebarrueta/5847611

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment