Skip to content

Commit

Permalink
Updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-alexandrov committed Feb 21, 2020
1 parent 86cc540 commit 479f013
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Instagram OAuth2 Strategy for OmniAuth.

Supports OAuth 2.0 server-side flow with new Instagram Basic Display API and Long Live Tokens. Read the Instagram docs for more details: https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions

Inspired by [OmniAuth Strategy for Facebook](https://github.com/simi/omniauth-facebook).

## Installing

Add to your `Gemfile`:
Expand All @@ -26,6 +28,57 @@ Rails.application.config.middleware.use OmniAuth::Builder do
end
```

## Configuring

You can configure several options, which you pass in to the `provider` method via a `Hash`:

| Option name | Default | Description |
|-------------------------------------|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `scope` | `'user_profile,user_media'` | A comma-separated list of permissions you want to request from the user. |
| `info_fields` | `'account_type,id,media_count,username'` | A comma-separated list of fields should be returned when getting the user's info (see more https://developers.facebook.com/docs/instagram-basic-display-api/reference/user). |
| `callback_url` | | Specify a custom callback URL used during the server-side flow. Note this must be allowed by your app configuration on Facebook (see 'Valid OAuth redirect URIs' under the 'Basic Display' settings section in the configuration for your Facebook app for more details). |
| `exchange_access_token_to_long_lived` | `true` | Should `access_token` be exchanged to a Long-Lived token during callback phase of OmniAuth (see more about Long-Lived tokens here: https://developers.facebook.com/docs/instagram-basic-display-api/guides/long-lived-access-tokens) |


## Auth Hash

Here's an example Auth Hash available in `request.env['omniauth.auth']`:

```
{
provider: 'instagram_graph',
uid: '1234567',
info: {
name: 'igor_alexandrov',
nickname 'igor_alexandrov'
},
credentials: {
token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
expires_at: 1321747205, # when the access token expires (it always will)
expires: true # this will always be true
},
extra: {
raw_info: {
account_type: 'PERSONAL',
id: '17841400519842852',
media_count: 211,
username: "igor_alexandrov"
}
}
}
```

## Long-Lived Tokens

Long-Lived Tokens are valid for 60 days. To be able to use token after, you need to refresh it. Here is a sample code, that will help.


``` ruby
client = Omniauth::InstagramGraph::LongLivedClient.new(ENV['INSTAGRAM_APP_ID'], ENV['INSTAGRAM_APP_SECRET'])
token = client.get_token(access_token: "<CURRENT LONG-LIVED TOKEN>")
refreshed = token.refresh
```

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Expand Down

0 comments on commit 479f013

Please sign in to comment.