-
-
Save josebarrueta/5847611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment