-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
gitlab.ex
39 lines (34 loc) · 981 Bytes
/
gitlab.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule Assent.Strategy.Gitlab do
@moduledoc """
Gitlab OAuth 2.0 strategy.
## Usage
config = [
client_id: "REPLACE_WITH_CLIENT_ID",
client_secret: "REPLACE_WITH_CLIENT_SECRET"
]
See `Assent.Strategy.OAuth2` for more.
"""
use Assent.Strategy.OAuth2.Base
@impl true
def default_config(_config) do
[
site: "https://gitlab.com",
authorize_url: "/oauth/authorize",
token_url: "/oauth/token",
user_url: "/api/v4/user",
authorization_params: [scope: "api read_user read_registry"],
auth_method: :client_secret_post
]
end
@impl true
def normalize(_config, user) do
{:ok, %{
"sub" => user["id"],
"name" => user["name"],
"preferred_username" => user["username"],
"picture" => user["avatar_url"],
"email" => user["email"],
"email_verified" => not is_nil(user["confirmed_at"])
}}
end
end