Class: Code0::Identities::Provider::Microsoft

Inherits:
BaseOauth
  • Object
show all
Defined in:
lib/code0/identities/provider/microsoft.rb

Instance Attribute Summary

Attributes inherited from BaseOauth

#config_loader

Instance Method Summary collapse

Methods inherited from BaseOauth

#initialize, #load_identity

Constructor Details

This class inherits a constructor from Code0::Identities::Provider::BaseOauth

Instance Method Details

#authorization_urlObject



27
28
29
# File 'lib/code0/identities/provider/microsoft.rb', line 27

def authorization_url
  "https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{config[:redirect_uri]}&response_mode=query&scope=email%20profile%20openid"
end

#base_urlObject



7
8
9
# File 'lib/code0/identities/provider/microsoft.rb', line 7

def base_url
  "https://graph.microsoft.com/"
end

#create_identity(response) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/code0/identities/provider/microsoft.rb', line 31

def create_identity(response, *)
  body = response.parsed_response

  identifier = body["sub"]
  firstname = body["givenname"]
  lastname = body["familyname"]
  email = body["email"]

  Identity.new(:microsoft, identifier, nil, email, firstname, lastname)
end

#token_payload(code) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/code0/identities/provider/microsoft.rb', line 15

def token_payload(code)
  { code: code,
    grant_type: "authorization_code",
    redirect_uri: config[:redirect_uri],
    client_id: config[:client_id],
    client_secret: config[:client_secret] }
end

#token_urlObject



11
12
13
# File 'lib/code0/identities/provider/microsoft.rb', line 11

def token_url
  "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
end

#user_details_urlObject



23
24
25
# File 'lib/code0/identities/provider/microsoft.rb', line 23

def user_details_url
  "https://graph.microsoft.com/oidc/userinfo"
end