package cn.ey.biz.module.system.framework.third_auth;

import cn.ey.biz.framework.third.auth.oauth.config.AuthConfig;
import cn.ey.biz.framework.third.auth.oauth.config.AuthSource;
import cn.ey.biz.framework.third.auth.oauth.request.AuthDefaultRequest;
import lombok.AllArgsConstructor;

import java.text.MessageFormat;

@AllArgsConstructor
public class AuthMicrosoftExtSource implements AuthSource {

    private AuthConfig config;

    public String authorize() {
        return MessageFormat.format("https://login.partner.microsoftonline.cn/{0}/oauth2/v2.0/authorize", config.getTenantId());
    }

    public String accessToken() {
        return MessageFormat.format("https://login.partner.microsoftonline.cn/{0}/oauth2/v2.0/token", config.getTenantId());
    }

    public String userInfo() {
        return "https://microsoftgraph.chinacloudapi.cn/v1.0/me";
    }

    @Override
    public String groupInfo(String identity) {
        return String.format("https://microsoftgraph.chinacloudapi.cn/v1.0/users/%s/memberOf", identity);
    }

    public String refresh() {
        return MessageFormat.format("https://login.partner.microsoftonline.cn/{0}/oauth2/v2.0/token", config.getTenantId());
    }

    public Class<? extends AuthDefaultRequest> getTargetClass() {
        return AuthMicrosoftCnExtRequest.class;
    }

    public String getName(){
        return "MICROSOFT_EXT";
    }

}
