Есть такой код из примера для авторизации по протоколу oauth для гугла.
////////////////////////////////
public partial class OAuthNativeFlowPage : ContentPage
{
Account account;
AccountStore store;
public OAuthNativeFlowPage()
{
InitializeComponent();
store = AccountStore.Create();
}
void OnLoginClicked(object sender, EventArgs e)
{
string clientId = null;
string redirectUri = null;
switch (Device.RuntimePlatform)
{
case Device.iOS:
clientId = Constants.iOSClientId;
redirectUri = Constants.iOSRedirectUrl;
break;
case Device.Android:
clientId = Constants.AndroidClientId;
redirectUri = Constants.AndroidRedirectUrl;
break;
}
account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
var authenticator = new OAuth2Authenticator(
clientId,
null,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
authenticator.Completed += OnAuthCompleted;
authenticator.Error += OnAuthError;
AuthenticationState.Authenticator = authenticator;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);
}
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
var authenticator = sender as OAuth2Authenticator;
if (authenticator != null)
{
authenticator.Completed -= OnAuthCompleted;
authenticator.Error -= OnAuthError;
}
User user = null;
if (e.IsAuthenticated)
{
// If the user is authenticated, request their basic user data from Google
// UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
var response = await request.GetResponseAsync();
if (response != null)
{
// Deserialize the data and store it in the account store
// The users email address will be used to identify data in SimpleDB
string userJson = await response.GetResponseTextAsync();
user = JsonConvert.DeserializeObject(userJson);
}
if (account != null)
{
store.Delete(account, Constants.AppName);
}
await store.SaveAsync(account = e.Account, Constants.AppName);
await DisplayAlert("Email address", user.Email, "OK");
}
}
void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
{
var authenticator = sender as OAuth2Authenticator;
if (authenticator != null)
{
authenticator.Completed -= OnAuthCompleted;
authenticator.Error -= OnAuthError;
}
Debug.WriteLine("Authentication error: " + e.Message);
}
}
///////////////////////////////////
Как его переделать под битрикс24? а точнее что вставлять в эти параметры?
var authenticator = new OAuth2Authenticator(
clientId,
null,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
Авторизированный юрл, редирект и ацес токен.
подставил
AuthorizeUrl = "https://profiescort.bitrix24.ru/oauth/authorize/?
AccessTokenUrl = "https://portal.bitrix24.com/oauth/authorize/?
RedirectUrl = "https://portal.bitrix24.com/oauth/authorize/?local.5c6e98674befd9.58558239"
Пишет приложение не найдено при ответе.
Даже так, первое время выдавал логин окошко битрикс, один раз залогинился, теперь пишет Приложение не найдено
////////////////////////////////
public partial class OAuthNativeFlowPage : ContentPage
{
Account account;
AccountStore store;
public OAuthNativeFlowPage()
{
InitializeComponent();
store = AccountStore.Create();
}
void OnLoginClicked(object sender, EventArgs e)
{
string clientId = null;
string redirectUri = null;
switch (Device.RuntimePlatform)
{
case Device.iOS:
clientId = Constants.iOSClientId;
redirectUri = Constants.iOSRedirectUrl;
break;
case Device.Android:
clientId = Constants.AndroidClientId;
redirectUri = Constants.AndroidRedirectUrl;
break;
}
account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
var authenticator = new OAuth2Authenticator(
clientId,
null,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
authenticator.Completed += OnAuthCompleted;
authenticator.Error += OnAuthError;
AuthenticationState.Authenticator = authenticator;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);
}
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
{
var authenticator = sender as OAuth2Authenticator;
if (authenticator != null)
{
authenticator.Completed -= OnAuthCompleted;
authenticator.Error -= OnAuthError;
}
User user = null;
if (e.IsAuthenticated)
{
// If the user is authenticated, request their basic user data from Google
// UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account);
var response = await request.GetResponseAsync();
if (response != null)
{
// Deserialize the data and store it in the account store
// The users email address will be used to identify data in SimpleDB
string userJson = await response.GetResponseTextAsync();
user = JsonConvert.DeserializeObject
}
if (account != null)
{
store.Delete(account, Constants.AppName);
}
await store.SaveAsync(account = e.Account, Constants.AppName);
await DisplayAlert("Email address", user.Email, "OK");
}
}
void OnAuthError(object sender, AuthenticatorErrorEventArgs e)
{
var authenticator = sender as OAuth2Authenticator;
if (authenticator != null)
{
authenticator.Completed -= OnAuthCompleted;
authenticator.Error -= OnAuthError;
}
Debug.WriteLine("Authentication error: " + e.Message);
}
}
///////////////////////////////////
Как его переделать под битрикс24? а точнее что вставлять в эти параметры?
var authenticator = new OAuth2Authenticator(
clientId,
null,
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
Авторизированный юрл, редирект и ацес токен.
подставил
AuthorizeUrl = "https://profiescort.bitrix24.ru/oauth/authorize/?
AccessTokenUrl = "https://portal.bitrix24.com/oauth/authorize/?
RedirectUrl = "https://portal.bitrix24.com/oauth/authorize/?local.5c6e98674befd9.58558239"
Пишет приложение не найдено при ответе.
Даже так, первое время выдавал логин окошко битрикс, один раз залогинился, теперь пишет Приложение не найдено
Для персональной подписи, участник не представляет организацию.
Нет комментариев
Предыдущие комментарии
для добавления комментариев необходимо авторизоваться
Горячие темы форума
Форум
09.06.2019 9 24.03.202015:06
Ошибка при нажатии на кнопку "КУПИТЬ"
Интернет магазин на Битрикс 2409.06.2019 9 24.03.202015:06
Форум
16.09.2019 6 22.10.202112:10
Личный кабинет клиента на сайт + интеграция с Битрикс24
Интернет магазин на Битрикс 2416.09.2019 6 22.10.202112:10