2010-04-01 4 views
3

나는이 주제에 관한 정보를 찾을 수있을 것이라고 생각했지만 현재 Google go-fu는 약하다. 저는 Amazon.com 제품 광고 API를 사용하는 Silverlight 앱을 제작하고 있습니다. 내 응용 프로그램에 인증을 추가하고 싶지만 기본 폼 기본 인증을 사용하는 대신 OpenId를 구현하고 싶습니다. 나는 그들의 공급자를 위해 Yahoo 또는 Google을 사용하는 많은 광경을 본다. 적어도 하나의 시력은 기억하지만, Amazon.com을 제공 업체로 사용한 것은 어떤 시력인지 기억하지 못합니다.Amazon.com을 인증 공급자로 사용할 수 있습니까

사람이이 문서의 올바른 방향으로 나를 가리킬 수 있다면 좋을 것입니다.

편집 : 이제 Amazon.com 로그인을 사용할 수있는 Target.com임을 기억합니다.

+0

, Target.com은의 따라서 공유, 구현 및 몇 년 동안 아마존 서비스에서 호스팅되었습니다 계정. 타겟은 몇 달 전에 자체 구현으로 진행되었다고 생각합니다. – fmr

답변

0

OpenID에 대해 많이 알지는 않지만 사용자 지정 authenticatin 서비스를 작성해야합니다. 그다지 나쁘지 않습니다. 당신이 코드를 통해 확인하는 방법을 알고 있다면 당신은 세 가지가 필요합니다 ..... 서버 측에

(그런데 아직도 실제로 convienent이다 폼 인증을 활용합니다). 사용자 데이터를 저장할 클래스, 양식 인증에서 상속하는 클래스 .. 및 로그온 예외를 처리하는 클래스 .. 여기

는 서버 코드의 예 (죄송 마이너스 오픈 ID 확인)

입니다
using System.ServiceModel.DomainServices.Server.ApplicationServices; 

public class UserDTO : UserBase 
{ 
    public string Email { get; set; } 

    //Must be string since will be included in HTTP Headers 
    public string Id { get; set; } 

    public bool CanCreateSomething { get; set;} 
} 

using System; using System.Data.Objects; using System.ServiceModel.DomainServices.Hosting;

[EnableClientAccess] 
public class CustomAuthenticationService : FormsAuthenticationService<UserDTO> 
{ 


    protected override UserDTO ValidateCredentials(string name, string password, string customData, 
                out string userData) 
    { 
     UserDTO user = null; 
     userData = null; 

     OpenIDUser OIDusr; 

     if OIDusr != null) 
     { 
      user = new UserDTO { Name = OIDusr.Description, Email = OIDusr.PrimaryEmail, Id= OIDusr.Id.ToString() }; 
     } 

     if (user != null) 
     { 
      //Set custom data fields for HTTP session 
      userData = user.PartyId + ":" + user.Email; 
     } 


     return user; 
    } 

} 클라이언트 측에

[Serializable] 
public class FormsAuthenticationLogonException : Exception 
{ 
    public FormsAuthenticationLogonException(string message) : base(message){} 
} 

public abstract class FormsAuthenticationService<TUser> : DomainService, IAuthentication<TUser> 
    where TUser : UserBase 
{ 
    #region IAuthentication<TUser> Members 

    public TUser GetUser() 
    { 
     var currentUser = ServiceContext.User; 
     if ((currentUser != null) && currentUser.Identity.IsAuthenticated) 
     { 
      var userIdentity = currentUser.Identity as FormsIdentity; 
      if (userIdentity != null) 
      { 
       var ticket = userIdentity.Ticket; 
       if (ticket != null) 
       { 
        return GetCurrentUser(currentUser.Identity.Name, ticket.UserData); 
       } 
      } 
     } 
     return GetDefaultUser(); 
    } 


    public TUser Login(string userName, string password, bool isPersistent, string customData) 
    { 
     string userData; 
     TUser user = ValidateCredentials(userName, password, customData, out userData); 
     if (user != null) 
     { 
      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(/* version */ 
       1, userName, DateTime.Now, DateTime.Now.AddMinutes(30), 
       isPersistent, userData, FormsAuthentication.FormsCookiePath); 
      string encryptedTicket = FormsAuthentication.Encrypt(ticket); 
      HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); 
      HttpContextBase httpContext = (HttpContextBase) ServiceContext.GetService(typeof (HttpContextBase)); 
      httpContext.Response.Cookies.Add(authCookie); 
     } 
     else 
     { 
      HttpContextBase httpContext = (HttpContextBase) ServiceContext.GetService(typeof (HttpContextBase)); 
      httpContext.AddError(new FormsAuthenticationLogonException("Username or password is not correct.")); 
     } 
     return user; 
    } 

    public TUser Logout() 
    { 
     FormsAuthentication.SignOut(); 
     return GetDefaultUser(); 
    } 

    public void UpdateUser(TUser user) 
    { 
     throw new NotImplementedException(); 
    } 

    #endregion 

    protected abstract TUser GetCurrentUser(string name, string userData); 

    protected virtual TUser GetDefaultUser() 
    { 
     return null; 
    } 

    protected abstract TUser ValidateCredentials(string name, string password, string customData, 
               out string userData); 
} 

..... 참고로

LoginParameters loginParameters = new LoginParameters(UserName, Password); 

     WebContextBase.Current.Authentication.Login(loginParameters, 
      delegate(LoginOperation operation)  
      {      
       if (operation.HasError)  
       { 
        App.IsBusy = false; 
        operation.MarkErrorAsHandled(); 
        UserName = string.Empty; 
        Password = string.Empty; 
        MessageBox.Show("Username or Password is incorrect!"); 
        return;     
       } 

       //Login Success 
       CustomAuthenticationContext authContext = new CustomAuthenticationContext(); 
       authContext.Load(authContext.GetUserQuery(), UserLoaded, false); 
      }, null); 
관련 문제