зеркало из https://github.com/microsoft/winsdkfb.git
Have successfully re-requested parameters now, but code still needs to detect missing permissions (app) and be able to force login UI for rerequest (FBSession).
This commit is contained in:
Родитель
c424df47fa
Коммит
bf42663cfb
|
@ -158,13 +158,14 @@ void FacebookDialog::ShowDialog(
|
|||
}
|
||||
|
||||
void FacebookDialog::ShowLoginDialog(
|
||||
PropertySet^ Parameters
|
||||
)
|
||||
{
|
||||
TypedEventHandler<WebView^, WebViewNavigationStartingEventArgs^>^ handler =
|
||||
ref new TypedEventHandler<WebView^, WebViewNavigationStartingEventArgs^>(
|
||||
this, &FacebookDialog::dialogWebView_LoginNavStarting);
|
||||
ShowDialog(ref new DialogUriBuilder(this,
|
||||
&FacebookDialog::BuildLoginDialogUrl), handler, nullptr);
|
||||
&FacebookDialog::BuildLoginDialogUrl), handler, Parameters);
|
||||
}
|
||||
|
||||
void FacebookDialog::ShowFeedDialog(
|
||||
|
@ -265,26 +266,36 @@ Uri^ FacebookDialog::BuildLoginDialogUrl(
|
|||
|
||||
uriString += L"&redirect_uri=" + GetRedirectUriString(L"login");
|
||||
|
||||
// App can pass in parameters to override defaults.
|
||||
if (Parameters)
|
||||
// Enumerate through all the parameters
|
||||
IIterator<IKeyValuePair<String^, Object^>^>^ first = Parameters->First();
|
||||
while (first && (first->HasCurrent))
|
||||
{
|
||||
if (Parameters->HasKey(ScopeKey))
|
||||
String^ Key = first->Current->Key;
|
||||
String^ Value = dynamic_cast<String^>(first->Current->Value);
|
||||
if (Value)
|
||||
{
|
||||
scope = (String^)Parameters->Lookup(ScopeKey);
|
||||
if (!String::CompareOrdinal(Key, ScopeKey))
|
||||
{
|
||||
scope = Value;
|
||||
}
|
||||
else if (!String::CompareOrdinal(Key, DisplayKey))
|
||||
{
|
||||
displayType = Value;
|
||||
}
|
||||
else if (!String::CompareOrdinal(Key, ResponseTypeKey))
|
||||
{
|
||||
responseType = Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
uriString += Amp + Key + EqualSign + Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (Parameters->HasKey(DisplayKey))
|
||||
{
|
||||
displayType = (String^)Parameters->Lookup(DisplayKey);
|
||||
}
|
||||
|
||||
if (Parameters->HasKey(ResponseTypeKey))
|
||||
{
|
||||
responseType = (String^)Parameters->Lookup(ResponseTypeKey);
|
||||
}
|
||||
first->MoveNext();
|
||||
}
|
||||
|
||||
uriString += L"&" + ScopeKey + EqualSign + scope + Amp + DisplayKey + EqualSign +
|
||||
uriString += Amp + ScopeKey + EqualSign + scope + Amp + DisplayKey + EqualSign +
|
||||
displayType + Amp + ResponseTypeKey + EqualSign + responseType;
|
||||
|
||||
return ref new Uri(uriString);
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace Facebook
|
|||
);
|
||||
|
||||
void ShowLoginDialog(
|
||||
Windows::Foundation::Collections::PropertySet^ Parameters
|
||||
);
|
||||
|
||||
void ShowFeedDialog(
|
||||
|
|
|
@ -522,7 +522,7 @@ task<FBResult^> FBSession::ShowLoginDialog(
|
|||
{
|
||||
try
|
||||
{
|
||||
m_dialog->ShowLoginDialog();
|
||||
m_dialog->ShowLoginDialog(Parameters);
|
||||
}
|
||||
catch (Exception^ ex)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,38 @@ MainPage::MainPage()
|
|||
s->WinAppId = winAppId;
|
||||
}
|
||||
|
||||
BOOL MainPage::DidGetAllRequestedPermissions(
|
||||
)
|
||||
{
|
||||
// TODO: Need to actually check permissions here.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MainPage::NavigateToOptionsPage()
|
||||
{
|
||||
LoginButton->Content = L"Logout";
|
||||
|
||||
// We're redirecting to a page that shows simple user info, so
|
||||
// have to dispatch back to the UI thread.
|
||||
CoreWindow^ wind = CoreApplication::MainView->CoreWindow;
|
||||
|
||||
if (wind)
|
||||
{
|
||||
CoreDispatcher^ disp = wind->Dispatcher;
|
||||
if (disp)
|
||||
{
|
||||
disp->RunAsync(
|
||||
Windows::UI::Core::CoreDispatcherPriority::Normal,
|
||||
ref new Windows::UI::Core::DispatchedHandler([this]()
|
||||
{
|
||||
LoginCpp::App^ a = dynamic_cast<LoginCpp::App^>(Application::Current);
|
||||
Windows::UI::Xaml::Controls::Frame^ f = a->CreateRootFrame();
|
||||
f->Navigate(OptionsPage::typeid);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainPage::login_OnClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
FBSession^ sess = FBSession::ActiveSession;
|
||||
|
@ -93,34 +125,32 @@ void MainPage::login_OnClicked(Platform::Object^ sender, Windows::UI::Xaml::Rout
|
|||
|
||||
PropertySet^ parameters = ref new PropertySet();
|
||||
|
||||
parameters->Insert(L"scope",
|
||||
parameters->Insert(L"scope",
|
||||
L"public_profile,user_friends,user_likes,user_groups,user_location");
|
||||
|
||||
create_task(sess->LoginAsync(parameters)).then([=](FBResult^ result)
|
||||
{
|
||||
if (result->Succeeded)
|
||||
{
|
||||
LoginButton->Content = L"Logout";
|
||||
if (DidGetAllRequestedPermissions())
|
||||
{
|
||||
NavigateToOptionsPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
PropertySet^ reRequestParams = ref new PropertySet();
|
||||
|
||||
// We're redirecting to a page that shows simple user info, so
|
||||
// have to dispatch back to the UI thread.
|
||||
CoreWindow^ wind = CoreApplication::MainView->CoreWindow;
|
||||
|
||||
if (wind)
|
||||
{
|
||||
CoreDispatcher^ disp = wind->Dispatcher;
|
||||
if (disp)
|
||||
{
|
||||
disp->RunAsync(
|
||||
Windows::UI::Core::CoreDispatcherPriority::Normal,
|
||||
ref new Windows::UI::Core::DispatchedHandler([this]()
|
||||
{
|
||||
LoginCpp::App^ a = dynamic_cast<LoginCpp::App^>(Application::Current);
|
||||
Windows::UI::Xaml::Controls::Frame^ f = a->CreateRootFrame();
|
||||
f->Navigate(OptionsPage::typeid);
|
||||
}));
|
||||
}
|
||||
}
|
||||
reRequestParams->Insert(L"scope",
|
||||
L"public_profile,user_friends,user_likes,user_groups,user_location");
|
||||
reRequestParams->Insert(L"auth_type", L"rerequest");
|
||||
create_task(sess->LoginAsync(reRequestParams)).then([=](FBResult^ result)
|
||||
{
|
||||
if (result->Succeeded)
|
||||
{
|
||||
NavigateToOptionsPage();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,6 +34,14 @@ namespace LoginCpp
|
|||
MainPage();
|
||||
|
||||
private:
|
||||
void login_OnClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
BOOL DidGetAllRequestedPermissions(
|
||||
);
|
||||
|
||||
void NavigateToOptionsPage(
|
||||
);
|
||||
|
||||
void login_OnClicked(
|
||||
Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче