2017-10-21 1 views
0

이전에 모바일 애플리케이션 백엔드로 Azure Mobile App을 사용 중이며 이제는 회사에서 웹 사이트 인터페이스를 개발하도록 요청했으며 현재 모든 사용자가 기존 계정으로 로그인 할 수 있어야합니다.Azure 웹 사이트가 모바일 앱과 다른 사용자 아이디 생성

내베이스 (link to guide)

모두 잘 작동으로 아드리안 방법을 사용하고 있습니다. 모바일 앱과 웹 사이트는 동일한 앱 서비스를 사용합니다. 웹 사이트를 제외하고 인증하는 경우 다른 사용자 ID가

웹 사이트 사용자

{푸른-URL} /. 인증/로그인/페이스 북

(내 경우 페이스 북 & 구글에서) 모바일 앱 비교 생성

사용자 ID : XXX

<div class="panel-body">   
    <a href="/.auth/login/facebook?post_login_redirect_url=/Home" class="btn btn-block btn-social btn-facebook"> 
    <i class="fa fa-facebook"></i> Sign in with Facebook 
    </a>    
</div> 

모바일 사용자

/인증/로그인/페이스 북 {푸른-URL을} LoginAsync()를 사용하거나 호출

사용자 ID :. SID : XXX

이것은 내 Startup.cs

public static void ConfigureMobileApp(IAppBuilder app) 
    { 
     HttpConfiguration config = new HttpConfiguration(); 

     new MobileAppConfiguration() 
      .AddTables(
       new MobileAppTableConfiguration() 
        .MapTableControllers() 
        .AddEntityFramework()) 
      .MapApiControllers() 
      .AddPushNotifications() 
      .ApplyTo(config); 

     // Use Entity Framework Code First to create database tables based on your DbContext 
     // Database.SetInitializer(new MobileServiceInitializer()); 
     var migrator = new DbMigrator(new Migrations.Configuration()); 
     migrator.Update(); 

     MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings(); 


     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new PathString("/Account/Login"), 
      Provider = new CookieAuthenticationProvider 
      { 
       OnApplyRedirect = ctx => 
       { 
        if (!IsZumoAuth(ctx.Request)) 
        { 

         ctx.Response.Redirect(ctx.RedirectUri); 
        } 
       } 
      } 

     }); 



     if (string.IsNullOrEmpty(settings.HostName)) 
     { 

      app.Use(typeof(CustomAppServiceAuthenticationMiddleware), app, new AppServiceAuthenticationOptions 
      //app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions 
      { 
       // This middleware is intended to be used locally for debugging. By default, HostName will 
       // only have a value when running in an App Service application. 
       SigningKey = ConfigurationManager.AppSettings["SigningKey"], 
       ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] }, 
       ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] }, 
       TokenHandler = config.GetAppServiceTokenHandler() 
      }); 
     } 



     app.UseWebApi(config); 
    } 

내가 빠뜨릴만한 것들이 있습니까?

답변

0

설명에 따르면 계정 사용자 ID와 쉬운 인증 끝점 사용자 ID를 오해 할 수도 있습니다.

내가 아는 한, 하늘색 모바일 앱 백엔드 또는 하늘색 웹 앱에서 아래 코드를 사용하면 사용자 ID를 얻을 수 있습니다. 동일한 ID를 얻을 수 있습니다.

var claimsPrincipal = this.User as ClaimsPrincipal; 
string sid = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier).Value; 

Id는 각 사용자의 계정 ID입니다.

원격 디버그를 사용하여 ID를 가져 오거나 {yourwebappname} .azurewebsites.com/.auth/me에 액세스하여 ID를 얻을 수 있습니다.

enter image description here

나는 모바일 앱은 SID는 다음과 같다 얻을 것 같아요 : 제 생각에는

enter image description here

에서, SID는 푸른 쉽게 인증 엔드 포인트 인 사용자 계정 ID를하지 생성합니다.

그래서 사용자 ID로 사용자 계정 ID를 사용하는 것이 좋습니다.

정보를 얻으려면 {yourwebappname}.azurewebsites.com/.auth/me으로 요청을 보내면 사용자 정보 json이 반환됩니다.

내 이미지와 같이이 json에서 사용자 계정 ID를 얻을 수 있습니다.

관련 문제