2016-02-24 36 views
6

kullanarak e-postada oturum açamazsınız Bu iletiyi http://dev.office.com/code-samples-detail/2142 ve Ruby'nin kullanıcı e-posta adresini almak için takip ettim. İşte kod: Bu fonksiyon çok iyi çalıştıOffice 365 REST API

# Parses an ID token and returns the user's email 
 
def get_email_from_id_token(id_token) 
 

 
    # JWT is in three parts, separated by a '.' 
 
    token_parts = id_token.split('.') 
 
    # Token content is in the second part 
 
    encoded_token = token_parts[1] 
 

 
    # It's base64, but may not be padded 
 
    # Fix padding so Base64 module can decode 
 
    leftovers = token_parts[1].length.modulo(4) 
 
    if leftovers == 2 
 
    encoded_token += '==' 
 
    elsif leftovers == 3 
 
    encoded_token += '=' 
 
    end 
 

 
    # Base64 decode (urlsafe version) 
 
    decoded_token = Base64.urlsafe_decode64(encoded_token) 
 

 
    # Load into a JSON object 
 
    jwt = JSON.parse(decoded_token) 
 

 
    # Email is in the 'preferred_username' field 
 
    email = jwt['preferred_username'] 
 
end

, ben kullanıcının e-posta adresi alabilirsiniz. Ancak bugün, bu işlev hala hatasız çalışıyor ancak JSON artık kullanıcının e-posta adresini içermiyor.
Birisi bana yardımcı olabilir mi? Kullanıcının e-posta adresini almak istiyorum. Teşekkür ederim !

cevap

10

Azure, v2 uygulama modeline yönelik bir değişiklik yaptı ve artık varsayılan olarak kullanıcı bilgilerini almıyorsunuz.

Hepiniz burada bu konuda bilgi edinebilir: https://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-preview-oidc-changes/ ama özetlemek için:

  • openid kapsamı size kullanıcı için Temel profil bilgilerinizi vermek için kullandı.

    # Scopes required by the app 
    SCOPES = [ 'openid', 
          'https://outlook.office.com/mail.read' ] 
    
    : Standart OpenID doğrultusunda değildi
  • Azure sen, o numune için bu bilgilere

erişmek bu biraz bulmak için profile kapsamını talep gerektirmektedir değiştirildi

Ve bunu değiştirin:

# Scopes required by the app 
SCOPES = [ 'openid', 
      'profile', 
      'https://outlook.office.com/mail.read' ] 
+0

hızlı cevap için teşekkür ederiz. Yarın şirkete geldiğimde bunu deneyeceğim. –

+0

Çalışıyor. Teşekkür ederim ! –

+0

Merhaba, takvim etkinliklerini ve ardından söz konusu etkinlikle ilişkili e-postayı almak için API kullanıyoruz. Bunu almak için şimdi ücretli bir hesap açmak zorunda mıyız? –

2

profil ekleyiniz ve kapsamı email:

SCOPES = [ 'Openid', 'profil', 'email', 'https://outlook.office.com/mail.read']

+0

Çalışıyor. Teşekkür ederim ! –

+0

Posta kullanmıyorsam, kullanıcıların profil bilgilerini alamıyorum, posta okuma iznini istemiyorum – Diego

İlgili konular