This flow is useful for obtaining an access token authorized for specific scopes when pushing the user into a browser-based flow is impractical for technical or user-experience reasons.
This is referred to as the Resource Owner Password Credential flow in the OAuth 2.0 spec. However, in order to protect the integrity of client_secret
s, we require the use of a separate token to be included with flows.
Your application must be specifically approved to use this flow. To obtain authorization, go to your App.net developer dashboard, select your app, and click Request approval for password flow. You will need to provide an explanation of your situation and then click the Submit Request button to complete your request for authorization. When your request has been approved you will receive an email with your password grant secret. The password grant secret token will also be available on your account page.
Security of user accounts is the most important thing. When in doubt, err on the side of securing user password information, rather than optimizing for user experience.
Some of these rules might limit what you can do with your app. Please do not attempt to circumvent them, or we will disable your application token. That may sound harsh, but it is of utmost importance that we protect the integrity of the service and the security of user accounts.
These flows should only be used in cases where browser-based authentication is impractical. For one-off applications, shell scripts, etc., please generate an access token for your app via My Apps.
By default users will receive an email each time they authorize an application with this flow listing the name of the application, the scopes requested and the time that authorization was performed.
Once you have been approved, using the password flow is pretty straightforward:
From your client, make a request to the token endpoint:
POST https://account.app.net/oauth/access_token
with URL-encoded POST body:
client_id=[your client ID]
&password_grant_secret=[your password grant secret, not your client secret]
&grant_type=password
&username=[user's email or username]
&password=[user's password]
&scope=[scopes separated by spaces]
Example:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password" \
-d "client_id=[your client_id]" -d "password_grant_secret=[your password grant secret that was emailed to you]" \
-d "username=[user's email address or username]" -d "password=[user's password]" \
-d "scope=[scopes separated by spaces]" "https://account.app.net/oauth/access_token"
The use of
password_grant_secret
diverges from the OAuth 2.0 specification.password_grant_secret
is a special token that we’ll send you when your use of the password flow is approved.
You can require app-specific passwords by providing a
require_app_specific_password=1
URL parameter. Two-Factor Auth users must use app-specific passwords regardless of this parameter. We strongly encourage the use of app-specific passwords by all users as they significantly increase account security.
If the authorization was successful, App.net will respond with a JSON-encoded token:
{"access_token": "[user access token]", "token": {...Token object...}}
You can use this access_token to make authenticated calls to the App.net API on behalf of a user.
If authentication failed or there was another error, App.net will respond with an error:
{"error": "Authentication failed"}
If the error_text
key is present in this dictionary, you MUST show a modal dialog or equivalent containing this text. If possible, you should include value of the error_title
key as a title in your dialog.