public async Task <UserResponse> GetUserProfile() { string sessionId, localId; if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId)) { return(null); } if (!await OAuthDB.IsSessionIdValid(sessionId, localId)) { return(null); } string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId); UserProfileApi userProfileApi = new UserProfileApi(); userProfileApi.Configuration.AccessToken = userAccessToken; try { dynamic user = await userProfileApi.GetUserProfileAsync(); UserResponse response = new UserResponse(); response.firstName = user.firstName; response.lastName = user.lastName; return(response); } catch (Exception e) { return(null); } }
private async Task <bool> IsAccountAdmin(string hubId, Credentials credentials) { UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credentials.TokenInternal; dynamic profile = await userApi.GetUserProfileAsync(); // 2-legged account:read token TwoLeggedApi oauth = new TwoLeggedApi(); dynamic bearer = await oauth.AuthenticateAsync(Config.GetAppSetting("FORGE_CLIENT_ID"), Config.GetAppSetting("FORGE_CLIENT_SECRET"), "client_credentials", new Scope[] { Scope.AccountRead }); RestClient client = new RestClient(Config.BaseUrl); RestRequest thisUserRequest = new RestRequest("/hq/v1/accounts/{account_id}/users/search?email={email}&limit=1", RestSharp.Method.GET); thisUserRequest.AddParameter("account_id", hubId.Replace("b.", string.Empty), ParameterType.UrlSegment); thisUserRequest.AddParameter("email", profile.emailId, ParameterType.UrlSegment); thisUserRequest.AddHeader("Authorization", "Bearer " + bearer.access_token); IRestResponse thisUserResponse = await client.ExecuteTaskAsync(thisUserRequest); dynamic thisUser = JArray.Parse(thisUserResponse.Content); string role = thisUser[0].role; return(role == "account_admin"); }
public async Task <JObject> GetUserProfileAsync() { Credentials credentials = await Credentials.FromSessionAsync(); if (credentials == null) { return(null); } // the API SDK UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credentials.TokenInternal; // get the user profile dynamic userProfile = await userApi.GetUserProfileAsync(); // prepare a response with name & picture dynamic response = new JObject(); response.name = string.Format("{0} {1}", userProfile.firstName, userProfile.lastName); response.picture = userProfile.profileImages.sizeX40; return(response); }
static Tuple <bool, string> DoLogin(string userName, string password) { var xChronosheetsAuth_example = ""; var apiLoginInstance = new UserProfileApi(); var wantsExit = false; try { var loginRequest = new CSDoLoginRequest(userName, password); var loginResult = apiLoginInstance.UserProfileDoLogin(loginRequest); if (loginResult.Status == CSApiResponseDoLoginResponse.StatusEnum.Succeeded) { xChronosheetsAuth_example = loginResult.Data.CSAuthToken; } else { Console.WriteLine("Error logging in: " + loginResult.Message); Console.WriteLine("Please try again, or press 'Q' to quit the app. Press enter to try again."); var input = Console.ReadLine().Trim().ToUpper(); if (input == "Q") { wantsExit = true; } } } catch (Exception e) { Console.WriteLine("Exception when calling UserProfileApi.UserProfileDoLogin: " + e.Message); wantsExit = true; Console.ReadKey(); } return(new Tuple <bool, string>(wantsExit, xChronosheetsAuth_example)); }
/// <summary> /// Get profile for the user with the access token. /// </summary> /// <param name="token">Oxygen access token.</param> /// <returns>Dynamic object with User Profile</returns> /// <remarks> /// User Profile fields: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/#body-structure-200 /// </remarks> public async Task <dynamic> GetProfileAsync(string token) { var api = new UserProfileApi(new Configuration { AccessToken = token }); return(await api.GetUserProfileAsync()); }
private static async Task <string> GetUserId(Credentials credentials) { UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credentials.TokenInternal; dynamic userProfile = await userApi.GetUserProfileAsync(); return(userProfile.userId); }
protected override void Initialize(MessengerCredentials credentials = null) { base.Initialize(credentials); Authenticator = new Authenticator(credentials); SendApi = new SendApi(credentials); UserProfileApi = new UserProfileApi(credentials); MessengerProfileAPI = new MessengerProfileAPI(credentials); }
/* * Unhandled exception rendering component: System.Net.Requests is not supported on this platform. * System.PlatformNotSupportedException: System.Net.Requests is not supported on this platform. * at System.Net.WebRequest.get_DefaultWebProxy() * at RestSharp.RestClient.ConfigureHttp(IRestRequest request) * at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, String httpMethod, Func`4 getWebRequest) * at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback, Method httpMethod) * at RestSharp.RestClient.ExecuteAsync(IRestRequest request, Action`2 callback) * at RestSharp.RestClient.ExecuteAsync(IRestRequest request, CancellationToken token) * --- End of stack trace from previous location --- * at Autodesk.Forge.Client.ApiClient.CallApiAsync(String path, Method method, Dictionary`2 queryParams, Object postBody, Dictionary`2 headerParams, Dictionary`2 formParams, Dictionary`2 fileParams, Dictionary`2 pathParams, String contentType) * at Autodesk.Forge.UserProfileApi.GetUserProfileAsyncWithHttpInfo() * at Autodesk.Forge.UserProfileApi.GetUserProfileAsync() * at BlazorImplicitGrantForge.Pages.Index.GetNameFromProfileAsync() in d:\Demos\BlazorImplicitGrantForge\BlazorImplicitGrantForge\Pages\Index.razor.cs:line 42 * at BlazorImplicitGrantForge.Pages.Index.OnInitializedAsync() in d:\Demos\BlazorImplicitGrantForge\BlazorImplicitGrantForge\Pages\Index.razor.cs:line 32 * at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() */ private async Task <string> GetNameFromProfileAsync() { UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = TokenService.AccessToken; dynamic userProfile = await userApi.GetUserProfileAsync().ConfigureAwait(false); return(string.Format("{0} {1}", userProfile.firstName, userProfile.lastName)); }
protected override void Initialize(Credentials credentials = null) { base.Initialize(credentials); Authenticator = new Authenticator(credentials); SendApi = new SendApi(credentials); UserProfileApi = new UserProfileApi(credentials); MessengerProfileAPI = new MessengerProfileAPI(credentials); HandoverProtocolHandler = new HandoverProtocolHandler(credentials); PageFeedApi = new PageFeedAPI(credentials); }
private async Task <bool> IsAccountAdmin(string hubId, string accountReadToken, Credentials credentials) { UserProfileApi userApi = new UserProfileApi(); userApi.Configuration.AccessToken = credentials.TokenInternal; dynamic profile = await userApi.GetUserProfileAsync(); RestClient client = new RestClient(BASE_URL); RestRequest thisUserRequest = new RestRequest("/hq/v1/accounts/{account_id}/users/search?email={email}&limit=1", RestSharp.Method.GET); thisUserRequest.AddParameter("account_id", hubId.Replace("b.", string.Empty), ParameterType.UrlSegment); thisUserRequest.AddParameter("email", profile.emailId, ParameterType.UrlSegment); thisUserRequest.AddHeader("Authorization", "Bearer " + accountReadToken); IRestResponse thisUserResponse = await client.ExecuteTaskAsync(thisUserRequest); dynamic thisUser = JArray.Parse(thisUserResponse.Content); string role = thisUser[0].role; return(role == "account_admin"); }
public void Init() { instance = new UserProfileApi(); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { AlbumApi = new AlbumApi(this); AnmmarApi = new AnmmarApi(this); AnnouncementApi = new AnnouncementApi(this); AssessmentsMessages = new AssessmentsMessages(this); AttendanceApi = new AttendanceApi(this); AuthorizationApi = new AuthorizationApi(this); BadgeApi = new BadgeApi(this); BehaviourApi = new BehaviourApi(this); CalendarApi = new CalendarApi(this); CertificateApi = new CertificateApi(this); ClassApi = new ClassApi(this); ConfigurationMangerApi = new ConfigurationMangerApi(this); CopyApi = new CopyApi(this); CourseApi = new CourseApi(this); CourseCatalogueApi = new CourseCatalogueApi(this); CourseGroupAuthors = new CourseGroupAuthors(this); CourseImageApi = new CourseImageApi(this); CourseRequestsApi = new CourseRequestsApi(this); CoursesProgress = new CoursesProgress(this); DiscussionApi = new DiscussionApi(this); EduShareApi = new EduShareApi(this); EvaluationApi = new EvaluationApi(this); EventApi = new EventApi(this); FileApi = new FileApi(this); FormsTemplatesApi = new FormsTemplatesApi(this); GradeApi = new GradeApi(this); GradeBookApi = new GradeBookApi(this); HelpApi = new HelpApi(this); IenApi = new IenApi(this); InvitationApi = new InvitationApi(this); InviteApi = new InviteApi(this); LanguageApi = new LanguageApi(this); LearningObjectivesApi = new LearningObjectivesApi(this); LearningPathApi = new LearningPathApi(this); LTILMSConsumerApi = new LTILMSConsumerApi(this); MaterialApi = new MaterialApi(this); MaterialSeenByUser = new MaterialSeenByUser(this); MembersApi = new MembersApi(this); MentorApi = new MentorApi(this); NotificationsApi = new NotificationsApi(this); OfferApi = new OfferApi(this); Office365 = new Office365(this); OfficeAddInApi = new OfficeAddInApi(this); Onenote = new Onenote(this); OrganizationUserAPI = new OrganizationUserAPI(this); OutcomesApi = new OutcomesApi(this); PointsApi = new PointsApi(this); PollApi = new PollApi(this); PrerequisitesApi = new PrerequisitesApi(this); QtiInteroperability = new QtiInteroperability(this); QuestionBankApi = new QuestionBankApi(this); ReflectionApi = new ReflectionApi(this); RelatedCoursesApi = new RelatedCoursesApi(this); ReportApi = new ReportApi(this); RoleManagementApi = new RoleManagementApi(this); ScheduleVisitApi = new ScheduleVisitApi(this); SchoolTypeApi = new SchoolTypeApi(this); SessionApi = new SessionApi(this); SpaceApi = new SpaceApi(this); StudentApi = new StudentApi(this); SubjectApi = new SubjectApi(this); SystemAdministrationApi = new SystemAdministrationApi(this); SystemReportsApi = new SystemReportsApi(this); TagsApi = new TagsApi(this); Themes = new Themes(this); TimeTableApi = new TimeTableApi(this); ToolConsumerProfileApi = new ToolConsumerProfileApi(this); TourApi = new TourApi(this); TrackApi = new TrackApi(this); TrainingPlanApi = new TrainingPlanApi(this); UserApi = new UserApi(this); UserProfileApi = new UserProfileApi(this); UserProgressApi = new UserProgressApi(this); UserSettingsApi = new UserSettingsApi(this); WallApi = new WallApi(this); BaseUri = new System.Uri("https://xwinji.azurewebsites.net"); SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); }