unsplash v1.1.0 Unsplash.Utils.OAuth View Source
Functions for user oAuth authentication.
Example usage:
Unsplash.OAuth.authorize_url!(scope: "public read_user write_user read_photos write_photos write_likes read_collections write_collections")
Unsplash.OAuth.authorize!(code: auth_code_from_the_callback_above)
Now all calls will be authorized.
Link to this section Summary
Functions
Builds the URL to the authorization endpoint.
Generates the authorization url which then authenticates with the user.
Builds the URL to token endpoint.
Link to this section Functions
authorize!(params \\ [], headers \\ [], options \\ []) View Source
authorize_url(client, params) View Source
Builds the URL to the authorization endpoint.
Example
def authorize_url(client, params) do
client
|> put_param(:response_type, "code")
|> put_param(:client_id, client.client_id)
|> put_param(:redirect_uri, client.redirect_uri)
|> merge_params(params)
end
Callback implementation for OAuth2.Strategy.authorize_url/2
.
authorize_url!(params \\ []) View Source
Generates the authorization url which then authenticates with the user.
The scope
option should be space seperated string of requested scopes.
Possible scopes:
public
Default. Read public data.read_user
Access user’s private data.write_user
Update the user’s profile.read_photos
Read private data from the user’s photos.write_photos
Upload photos on the user’s behalf.write_likes
Like or unlike a photo on the user’s behalfwrite_followers
Follow or unfollow a user on the user’s behalf.read_collections
View a user’s private collections.write_collections
Create and update a user’s collections.
Examples
iex> url = Unsplash.Utils.OAuth.authorize_url! scope: "public read_user write_user read_photos write_photos write_likes read_collections write_collections" iex> is_binary(url) true
get_access_token() View Source
get_token(client, params, headers) View Source
Builds the URL to token endpoint.
Example
def get_token(client, params, headers) do
client
|> put_param(:code, params[:code])
|> put_param(:grant_type, "authorization_code")
|> put_param(:client_id, client.client_id)
|> put_param(:client_secret, client.client_secret)
|> put_param(:redirect_uri, client.redirect_uri)
|> merge_params(params)
|> put_headers(headers)
end
Callback implementation for OAuth2.Strategy.get_token/3
.