Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Normalize auth tokens

  • Loading branch information...
commit 574627eca19e8c5a17d5370e91090b7b2f8fb592 1 parent 2016ecc
@dvv authored
View
11 src/cowboy_social_github.erl
@@ -90,7 +90,7 @@ get_user_profile(Auth, Req, Opts) ->
])
of
{ok, Profile} ->
- finish({ok, normalize_profile(Auth, Profile)}, Req, Opts);
+ finish({ok, normalize_auth(Auth), normalize_profile(Profile)}, Req, Opts);
_ ->
finish({error, noprofile}, Req, Opts)
catch _:_ ->
@@ -129,7 +129,14 @@ token_url() ->
profile_url() ->
<<"https://api.github.com/user">>.
-normalize_profile(_Auth, Raw) ->
+normalize_auth(Auth) ->
+ [
+ {access_token, key(<<"access_token">>, Auth)},
+ {token_type, key(<<"token_type">>, Auth)},
+ {expires_in, 0}
+ ].
+
+normalize_profile(Raw) ->
[
{id, << "github:",
(list_to_binary(integer_to_list(key(<<"id">>, Raw))))/binary >>},
View
11 src/cowboy_social_google.erl
@@ -92,7 +92,7 @@ get_user_profile(Auth, Req, Opts) ->
])
of
{ok, Profile} ->
- finish({ok, normalize_profile(Auth, Profile)}, Req, Opts);
+ finish({ok, normalize_auth(Auth), normalize_profile(Profile)}, Req, Opts);
_ ->
finish({error, noprofile}, Req, Opts)
catch _:_ ->
@@ -131,7 +131,14 @@ token_url() ->
profile_url() ->
<<"https://www.googleapis.com/oauth2/v1/userinfo">>.
-normalize_profile(_Auth, Raw) ->
+normalize_auth(Auth) ->
+ [
+ {access_token, key(<<"access_token">>, Auth)},
+ {token_type, key(<<"token_type">>, Auth)},
+ {expires_in, key(<<"expires_in">>, Auth)}
+ ].
+
+normalize_profile(Raw) ->
[
{id, << "google:", (key(<<"id">>, Raw))/binary >>},
{provider, <<"google">>},
View
14 src/cowboy_social_mailru.erl
@@ -89,8 +89,7 @@ get_user_profile(Auth, Req, Opts) ->
"app_id=", (key(client_id, Opts))/binary,
"method=users.getInfosecure=1session_key=",
(key(<<"access_token">>, Auth))/binary,
- (key(secret_key, Opts))/binary >>
- ),
+ (key(secret_key, Opts))/binary >>),
try cowboy_request:get_json(profile_url(), [
{<<"app_id">>, key(client_id, Opts)},
{<<"method">>, <<"users.getInfo">>},
@@ -100,7 +99,7 @@ get_user_profile(Auth, Req, Opts) ->
])
of
{ok, Profile} ->
- finish({ok, normalize_profile(Auth, Profile)}, Req, Opts);
+ finish({ok, normalize_auth(Auth), normalize_profile(Profile)}, Req, Opts);
_ ->
finish({error, noprofile}, Req, Opts)
catch _:_ ->
@@ -143,7 +142,14 @@ token_url() ->
profile_url() ->
<<"http://www.appsmail.ru/platform/api">>.
-normalize_profile(_Auth, [Raw]) ->
+normalize_auth(Auth) ->
+ [
+ {access_token, key(<<"access_token">>, Auth)},
+ {token_type, key(<<"token_type">>, Auth)},
+ {expires_in, key(<<"expires_in">>, Auth)}
+ ].
+
+normalize_profile([Raw]) ->
[
{id, << "mailru:", (key(<<"uid">>, Raw))/binary >>},
{provider, <<"mailru">>},
View
11 src/cowboy_social_vkontakte.erl
@@ -92,7 +92,7 @@ get_user_profile(Auth, Req, Opts) ->
])
of
{ok, Profile} ->
- finish({ok, normalize_profile(Auth, Profile)}, Req, Opts);
+ finish({ok, normalize_auth(Auth), normalize_profile(Profile)}, Req, Opts);
_ ->
finish({error, noprofile}, Req, Opts)
catch _:_ ->
@@ -131,7 +131,14 @@ token_url() ->
profile_url() ->
<<"https://api.vk.com/method/users.get">>.
-normalize_profile(_Auth, Raw0) ->
+normalize_auth(Auth) ->
+ [
+ {access_token, key(<<"access_token">>, Auth)},
+ {token_type, <<"Bearer">>},
+ {expires_in, key(<<"expires_in">>, Auth)}
+ ].
+
+normalize_profile(Raw0) ->
% NB: provider returns list of data for uids; we need only the first
[Raw] = key(<<"response">>, Raw0),
[
View
11 src/cowboy_social_yandex.erl
@@ -93,7 +93,7 @@ get_user_profile(Auth, Req, Opts) ->
])
of
{ok, Profile} ->
- finish({ok, normalize_profile(Auth, Profile)}, Req, Opts);
+ finish({ok, normalize_auth(Auth), normalize_profile(Profile)}, Req, Opts);
_ ->
finish({error, noprofile}, Req, Opts)
catch _:_ ->
@@ -132,7 +132,14 @@ token_url() ->
profile_url() ->
<<"https://login.yandex.ru/info">>.
-normalize_profile(_Auth, Raw) ->
+normalize_auth(Auth) ->
+ [
+ {access_token, key(<<"access_token">>, Auth)},
+ {token_type, key(<<"token_type">>, Auth)},
+ {expires_in, 0}
+ ].
+
+normalize_profile(Raw) ->
[
{id, << "yandex:", (key(<<"id">>, Raw))/binary >>},
{provider, <<"yandex">>},
Please sign in to comment.
Something went wrong with that request. Please try again.